- definitions singleton controller (theme default, first or create) with a repeater on data: type dropdown (url plus registry types), reference dependsOn type through signpost.ReferenceOptions - Settings page entries: Sitemap (link to the controller) and Sitemap settings (form), both behind golem15.sitemap.access_definitions - en and pl phrasebooks with the PHP keys - README with the PHP parity rules, tiers, hooks, commands and the Winter YAML adaptations - TestSitemapAdminSmoke: singleton, PHP-keyed rows, 422 on a foreign reference, settings save, 403 without the permission
49 lines
1.8 KiB
Go
49 lines
1.8 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/lagoon"
|
|
)
|
|
|
|
// DefinitionTheme is the fixed theme key of the one sitemap definition of an
|
|
// application (D-11). The theme column stays so the table matches PHP; the
|
|
// import commands write this key whatever the PHP theme was.
|
|
const DefinitionTheme = "default"
|
|
|
|
// Definition is a sitemap definition stored on golem15_sitemap_definitions,
|
|
// the PHP Golem15\Sitemap\Models\Definition. Data holds the items as JSON
|
|
// text (PHP $jsonable data).
|
|
type Definition struct {
|
|
ID uint `gorm:"column:id;primaryKey"`
|
|
Theme *string `gorm:"column:theme"`
|
|
Data lagoon.Jsonable[DefinitionItems] `gorm:"column:data"`
|
|
CreatedAt *time.Time `gorm:"column:created_at"`
|
|
UpdatedAt *time.Time `gorm:"column:updated_at"`
|
|
}
|
|
|
|
func (Definition) TableName() string { return "golem15_sitemap_definitions" }
|
|
|
|
// MorphName is the PHP class string of the model.
|
|
func (Definition) MorphName() string { return `Golem15\Sitemap\Models\Definition` }
|
|
|
|
// Fillable is exactly theme and data, the PHP $fillable with $guarded = ['*']
|
|
// (MassAssignmentTest).
|
|
func (Definition) Fillable() []string { return []string{"theme", "data"} }
|
|
|
|
// Rules is empty: the PHP model validated nothing. The admin form checks
|
|
// each item row's reference against its type.
|
|
func (Definition) Rules() map[string]string { return map[string]string{} }
|
|
|
|
// Items returns the stored items.
|
|
func (d Definition) Items() []DefinitionItem { return d.Data.Get() }
|
|
|
|
// SetItems stores items as the definition's data.
|
|
func (d *Definition) SetItems(items []DefinitionItem) {
|
|
d.Data = lagoon.Jsonable[DefinitionItems]{Data: DefinitionItems(items), Valid: true}
|
|
}
|
|
|
|
func init() {
|
|
Register(Definition{})
|
|
}
|