CategoryFormTrait
Add/edit form of a discussion category.
Multilingual fields (name, URL, editor info, meta tags); untranslated: the parent category
(tree), the "free" flag and the price list for founding a topic in a paid category (the same matrix as
advert categories: payment region x gateway, the currency of the gateway's region, supply kind). The table cms_mod_discussion_categories has no active /
toped_first columns (unlike the blog), so those toggles are absent. The Api maintains the
nested-set indexes (lft/rgt/level): save() inserts a new node, moveSubtree() handles
a parent change. The main photo is saved through $meta and the Api afterSave (builds the
variants, sets the FK). The skeleton comes from
BasePresenter::createForm().
Table of Contents
Methods
- createComponentEditForm() : Form
- addCategoryPriceMatrix() : void
- Price matrix of the category: for each payment region x payment gateway a price field and an active checkbox (the currency is that of the gateway's region relation, falling back to the region currency). The presenter supplies the axes (`$this->categoryRegions`, `categoryGates`). Applies when the category is not free.
- addStructureFields() : void
- Adds the structure fields: parent category (tree), icon CSS class, "free" flag and the main photo.
- addTranslationFields() : void
- Adds the multilingual fields, one set per language (`<field>_<langId>`), required when the language checkbox is on.
- buildCategoryEntity() : Category
- buildCategoryPrices() : ArrayCollection<int, CategoryPrice>
- Builds the owned `CategoryPrice` collection from the price matrix.
- collectImageMeta() : array<string, mixed>
- Builds `$meta` for the save: a new image (base64) and/or the delete flag.
- isHrefUnique() : bool
- Validates `href` uniqueness in the given language against other categories (the edited category is ignored). An empty `href` (nullable) is not checked.
- saveCategoryForm() : bool
- setCategoryFormDefaults() : void
Methods
createComponentEditForm()
protected
createComponentEditForm() : Form
Return values
FormaddCategoryPriceMatrix()
Price matrix of the category: for each payment region x payment gateway a price field and an active checkbox (the currency is that of the gateway's region relation, falling back to the region currency). The presenter supplies the axes (`$this->categoryRegions`, `categoryGates`). Applies when the category is not free.
private
addCategoryPriceMatrix(Form $form) : void
Parameters
- $form : Form
addStructureFields()
Adds the structure fields: parent category (tree), icon CSS class, "free" flag and the main photo.
private
addStructureFields(Form $form) : void
Parameters
- $form : Form
addTranslationFields()
Adds the multilingual fields, one set per language (`<field>_<langId>`), required when the language checkbox is on.
private
addTranslationFields(Form $form) : void
Parameters
- $form : Form
buildCategoryEntity()
private
buildCategoryEntity(ArrayHash<string|int, mixed> $values) : Category
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
CategorybuildCategoryPrices()
Builds the owned `CategoryPrice` collection from the price matrix.
private
buildCategoryPrices(ArrayHash<string|int, mixed> $values) : ArrayCollection<int, CategoryPrice>
An empty cell means no row, the same as the tariff price list (the front end offers only stored rows). Building every combination of payment region x gateway made a save without changes add 21 rows with price 0 (admin walkthrough A16). Rows outside the matrix axis (another currency for a region and gateway, a region or gateway that is not offered) are not edited by the form and are carried over unchanged. The currency must match the front end lookup (CategoryPriceGridTrait).
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
ArrayCollection<int, CategoryPrice>collectImageMeta()
Builds `$meta` for the save: a new image (base64) and/or the delete flag.
private
collectImageMeta(ArrayHash<string|int, mixed> $values) : array<string, mixed>
The Api turns it into an Asset (variants) and sets the FK to the main image.
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
array<string, mixed>isHrefUnique()
Validates `href` uniqueness in the given language against other categories (the edited category is ignored). An empty `href` (nullable) is not checked.
private
isHrefUnique(TextInput $input, int $langId) : bool
Parameters
- $input : TextInput
- $langId : int
Return values
boolsaveCategoryForm()
private
saveCategoryForm(ArrayHash<string|int, mixed> $values) : bool
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
boolsetCategoryFormDefaults()
private
setCategoryFormDefaults(Form $form) : void
Parameters
- $form : Form