PageSectionFormTrait
Add/edit form of a page section (`Admin:System:PageSection`).
The skeleton comes from BasePresenter::createForm(). Untranslated:
key (only on creation, see self::addKeyField()), note, global active. Translated
per language: title and content.
IMPORTANT: content goes through Form::addRawEditor(), not addEditor(). Sections are
output on the front end 1:1 as authored, and the full mode would silently strip Bootstrap
markup (<button>, <svg>, custom elements, unapproved attributes). raw is not sanitized
on the server either, so only this admin screen behind RBAC may fill it, never the front end.
Table of Contents
Methods
- createComponentEditForm() : Form
- addKeyField() : void
- Adds the `key` field. The `key` is the address a template or component calls by name, so it is not editable after creation; renaming would break front-end templates.
- addTranslationFields() : void
- Multilingual fields: title and HTML content per language, active by checkbox.
- buildPageSectionEntity() : PageSection
- savePageSectionForm() : bool
- Saves the form data. The redirect is done by {@see \App\Core\Base\Admin\BasePresenter::createForm()}.
- setPageSectionFormDefaults() : void
- tr() : string
- Translates a key in the form domain to a finished string (for `strtr()` messages with substituted values).
- validateKeyUniqueness() : bool
- Reports a `key` collision as a readable message instead of an SQL duplicate-key crash; the check runs before saving (see {@see PageFormTrait::validateHrefUniqueness()}).
Methods
createComponentEditForm()
protected
createComponentEditForm() : Form
Return values
FormaddKeyField()
Adds the `key` field. The `key` is the address a template or component calls by name, so it is not editable after creation; renaming would break front-end templates.
private
addKeyField(Form $form, callable(string): string $t) : void
IMPORTANT: immutability is not done by a hidden field plus addError(). addError() on a
hidden field only becomes a form-level error, and a hidden key could be forged by the
client. Instead, on edit the Nette control is not created at all (this method is called
only from the add branch), so a forged key POST value is never read:
self::savePageSectionForm() keeps the value of $this->editedPageSection. The
edit template prints the key as plain text, not as an <input>.
Parameters
- $form : Form
- $t : callable(string): string
addTranslationFields()
Multilingual fields: title and HTML content per language, active by checkbox.
private
addTranslationFields(Form $form) : void
Parameters
- $form : Form
buildPageSectionEntity()
private
buildPageSectionEntity(ArrayHash<string|int, mixed> $values) : PageSection
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
PageSectionsavePageSectionForm()
Saves the form data. The redirect is done by {@see \App\Core\Base\Admin\BasePresenter::createForm()}.
private
savePageSectionForm(ArrayHash<string|int, mixed> $values) : bool
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
boolsetPageSectionFormDefaults()
private
setPageSectionFormDefaults(Form $form) : void
Parameters
- $form : Form
tr()
Translates a key in the form domain to a finished string (for `strtr()` messages with substituted values).
private
tr(string $key) : string
Parameters
- $key : string
Return values
stringvalidateKeyUniqueness()
Reports a `key` collision as a readable message instead of an SQL duplicate-key crash; the check runs before saving (see {@see PageFormTrait::validateHrefUniqueness()}).
private
validateKeyUniqueness(ArrayHash<string|int, mixed> $values) : bool
Called only from savePageSectionForm(), so only when the key control exists (add);
on edit $values->key is never read (see self::addKeyField()).
Parameters
- $values : ArrayHash<string|int, mixed>