feat(17-04): FAQ plugin tracer, admin FAQ with sanitized question repeater

- golem15.faq plugin (Requires golem15.translate), table golem15_faq_faqs with the PHP columns
- FAQ model with jsonable content and the translate Locale relation
- admin controller golem15.faq.faqs: name, slug, locale, active switch, richeditor description, question repeater
- navigation FAQ (order 500), permission golem15.faq.faqs, en and pl phrasebooks
- TestFaqAdminSmoke: answers stored sanitized with a notice under content.1.answer
This commit is contained in:
2026-10-12 17:24:52 +02:00
commit 1c5491232a
22 changed files with 1370 additions and 0 deletions

57
models/faq.go Normal file
View File

@@ -0,0 +1,57 @@
package models
import (
"time"
translate "git.golem15.com/golem15/sm-translate-plugin/models"
"git.golem15.com/golem15/summercms/modules/lagoon"
)
// Content is the stored question and answer list: the PHP $jsonable content,
// one {question, answer} object per row.
type Content = []map[string]any
// FAQ is one FAQ in one locale, stored on golem15_faq_faqs: the PHP
// Golem15\FAQ\Models\FAQ. A site keeps one row per locale under the same
// slug, told apart by locale_id (the translate Locale).
type FAQ struct {
ID uint `gorm:"column:id;primaryKey"`
Name string `gorm:"column:name"`
Slug string `gorm:"column:slug"`
LocaleID uint `gorm:"column:locale_id"`
Locale *translate.Locale `gorm:"foreignKey:LocaleID" json:"-"`
IsActive bool `gorm:"column:is_active"`
Description *string `gorm:"column:description"`
Content lagoon.Jsonable[Content] `gorm:"column:content"`
CreatedAt *time.Time `gorm:"column:created_at"`
UpdatedAt *time.Time `gorm:"column:updated_at"`
}
func (FAQ) TableName() string { return "golem15_faq_faqs" }
// MorphName is the PHP class string of the model.
func (FAQ) MorphName() string { return `Golem15\FAQ\Models\FAQ` }
// Fillable is the list an admin save may set. The locale is set through the
// locale relation field, which writes locale_id.
func (FAQ) Fillable() []string {
return []string{"name", "slug", "locale_id", "is_active", "description", "content"}
}
// Rules require a name and a slug. The locale is required too, but the admin
// sets locale_id from the locale relation field after validation, so the
// controller checks it once the row is written (a missing locale rolls the
// save back).
func (FAQ) Rules() map[string]string {
return map[string]string{
"name": "required",
"slug": "required",
}
}
// Items returns the stored rows.
func (f FAQ) Items() Content { return f.Content.Get() }
func init() {
Register(FAQ{})
}

33
models/faq/columns.yaml Normal file
View File

@@ -0,0 +1,33 @@
# ===================================
# List Column Definitions
# ===================================
#
# The PHP columns plus locale: one slug exists per language, and without the
# column two rows of the same FAQ look identical.
columns:
id:
label: golem15.faq::lang.models.general.id
searchable: true
name:
label: golem15.faq::lang.labels.name
searchable: true
slug:
label: golem15.faq::lang.labels.slug
searchable: true
locale:
label: golem15.faq::lang.labels.locale
relation: locale
select: name
is_active:
label: golem15.faq::lang.labels.is_active
type: switch
created_at:
label: golem15.faq::lang.models.general.created_at
type: datetime
sortable: true
invisible: true
updated_at:
label: golem15.faq::lang.models.general.updated_at
type: datetime
sortable: true

50
models/faq/fields.yaml Normal file
View File

@@ -0,0 +1,50 @@
# ===================================
# Form Field Definitions
# ===================================
#
# Adapted from the WinterCMS form: span none with cssClass columns became
# left and right, the locale relation's select became nameFrom, and the
# fields carry comments for the locale and active switches.
fields:
name:
label: golem15.faq::lang.labels.name
type: text
span: left
required: true
slug:
label: golem15.faq::lang.labels.slug
type: text
span: right
required: true
preset: name
locale:
label: golem15.faq::lang.labels.locale
comment: golem15.faq::lang.labels.locale_comment
type: relation
nameFrom: name
span: left
required: true
is_active:
label: golem15.faq::lang.labels.is_active
comment: golem15.faq::lang.labels.is_active_comment
type: switch
span: right
description:
label: golem15.faq::lang.labels.description
type: richeditor
span: full
content:
label: golem15.faq::lang.labels.content
type: repeater
prompt: golem15.faq::lang.labels.add_question
titleFrom: question
form:
fields:
question:
label: golem15.faq::lang.labels.question
type: text
required: true
answer:
label: golem15.faq::lang.labels.answer
type: richeditor

15
models/registry.go Normal file
View File

@@ -0,0 +1,15 @@
// Package models holds the FAQ plugin's GORM models.
package models
var all []any
// Register appends GORM models so later files add models without editing
// plugin.go.
func Register(models ...any) {
all = append(all, models...)
}
// All returns every model registered by this package.
func All() []any {
return all
}