AdvertCategoryFieldsTrait
Profile categories as the multiplier `categories`: each row is a category picker (suggest and the `:Admin:Comcat:Category` modal) plus a `paid` checkbox.
The categories decide which dynamic parameters are shown. The picker works normally through the
presenter PickerHostTrait (the form is a
child of the presenter as editForm, no walk-up); pickers() registers the
configuration and the modal and suggest signals go to the presenter.
Edit prefills the rows from advert.categoryRels (category and paid from the database), so
paid is preserved. Save turns the rows {categoryId, paid} (extractCategoryRows())
into the object-graph collection AdvertCategoryRel
(AdvertFormTrait::applyCategoryRels()), persisted by the Api with cascade and orphanRemoval.
Table of Contents
Constants
- REGION_PARAMETER_TYPES : array<string|int, mixed> = [\App\Core\Base\Shared\Shared\Models\Entities\P...
- Parameter types that carry the profile region (tree picker and municipality or postcode suggest).
Methods
- pickers() : array<string, PickerConfig>
- Returns the presenter picker configuration (the {@see \App\UI\Admin\System\Presenters\Traits\Pickers\PickerHostTrait} contract).
- addCategoryFields() : void
- buildCategoryRowDefaults() : array<int, array{categoryId: int, category: string, paid: bool}>
- Builds the category row defaults from the edited profile (`categoryId`, label and `paid` from the database).
- buildRegionPreviewFieldMap() : array<string, string>
- Builds the preview after selecting a municipality: item data key to the form key of the parameter `city`, `zip` or `country` (only parameters the current form categories have).
- categoryMultiPicker() : PickerConfig
- categoryName() : string
- extractCategoryRows() : array<int, array{categoryId: int, paid: bool}>
- Builds flat rows `{categoryId, paid}` from the submitted multiplier rows; the input for {@see AdvertFormTrait::applyCategoryRels()} (object-graph collection), not a meta key. Deduplicated, positive `categoryId`.
- guardCategoriesSelected() : void
- Enforces at least one selected category; called from `onValidate`.
- resolveAnyRegionParameterField() : array{key: string, type: int}|null
- Returns the region parameter from the code list, independent of the selected category; used only to register the picker so suggest works on the add form too. Returns the first active root parameter of type `SELECT_REGION` (or legacy 37) or `REGION_PICKER`; null means the module has no region parameter.
- resolveCategoryLabel() : string|null
- resolveRegionParameterField() : array{key: string, type: int}|null
- Returns the form field of the region parameter: `key` is `parameter_<id>` (the picker `targetField`) and `type` decides the picker (`SELECT_REGION` or legacy 37: tree picker, `REGION_PICKER`: municipality or postcode suggest). Null means the system has no region parameter, so no picker is registered.
- suggestCategories() : array<int, array{id: int, label: string}>
Constants
REGION_PARAMETER_TYPES
Parameter types that carry the profile region (tree picker and municipality or postcode suggest).
private
array<string|int, mixed>
REGION_PARAMETER_TYPES
= [\App\Core\Base\Shared\Shared\Models\Entities\ParameterType::SELECT_REGION, \App\Core\Form\Parameters\SelectRegionHandler::LEGACY_REGION_WITH_POSTCODE, \App\Core\Base\Shared\Shared\Models\Entities\ParameterType::REGION_PICKER]
Methods
pickers()
Returns the presenter picker configuration (the {@see \App\UI\Admin\System\Presenters\Traits\Pickers\PickerHostTrait} contract).
protected
pickers() : array<string, PickerConfig>
Return values
array<string, PickerConfig>addCategoryFields()
private
addCategoryFields(Form $form) : void
Parameters
- $form : Form
buildCategoryRowDefaults()
Builds the category row defaults from the edited profile (`categoryId`, label and `paid` from the database).
private
buildCategoryRowDefaults() : array<int, array{categoryId: int, category: string, paid: bool}>
Return values
array<int, array{categoryId: int, category: string, paid: bool}>buildRegionPreviewFieldMap()
Builds the preview after selecting a municipality: item data key to the form key of the parameter `city`, `zip` or `country` (only parameters the current form categories have).
private
buildRegionPreviewFieldMap() : array<string, string>
Return values
array<string, string>categoryMultiPicker()
private
categoryMultiPicker([string $container = 'categories' ][, string $targetField = 'categoryId' ][, string $displayField = 'category' ]) : PickerConfig
Parameters
- $container : string = 'categories'
- $targetField : string = 'categoryId'
- $displayField : string = 'category'
Return values
PickerConfigcategoryName()
private
categoryName(Category $category) : string
Parameters
- $category : Category
Return values
stringextractCategoryRows()
Builds flat rows `{categoryId, paid}` from the submitted multiplier rows; the input for {@see AdvertFormTrait::applyCategoryRels()} (object-graph collection), not a meta key. Deduplicated, positive `categoryId`.
private
extractCategoryRows(ArrayHash $values) : array<int, array{categoryId: int, paid: bool}>
Parameters
- $values : ArrayHash
Return values
array<int, array{categoryId: int, paid: bool}>guardCategoriesSelected()
Enforces at least one selected category; called from `onValidate`.
private
guardCategoriesSelected(Form $form, ArrayHash $values) : void
Checked only on a real save (update or save). Add, remove and parametersRefresh are UI
submitters with setValidationScope([]) whose only job is the AJAX redraw, but Nette runs
onValidate for them too (Container::validate() calls the handlers
regardless of scope); without this gate "Add category" would report an error.
IMPORTANT: the error must go to a concrete component, not the form. The admin templates do
not render form-level errors (only the flash), and HiddenField::addError() is hard-wired
to form level. The carrier is therefore the "Add category" button (multiplier_creator), the
only component always rendered in the categories section, even with zero rows; the template
prints the error below it (Advert/Tabs/_form.latte). Form level is only a fallback
when the multiplier has no such button (maxCopies).
Parameters
- $form : Form
- $values : ArrayHash
resolveAnyRegionParameterField()
Returns the region parameter from the code list, independent of the selected category; used only to register the picker so suggest works on the add form too. Returns the first active root parameter of type `SELECT_REGION` (or legacy 37) or `REGION_PICKER`; null means the module has no region parameter.
private
resolveAnyRegionParameterField() : array{key: string, type: int}|null
Return values
array{key: string, type: int}|nullresolveCategoryLabel()
private
resolveCategoryLabel(int $id) : string|null
Parameters
- $id : int
Return values
string|nullresolveRegionParameterField()
Returns the form field of the region parameter: `key` is `parameter_<id>` (the picker `targetField`) and `type` decides the picker (`SELECT_REGION` or legacy 37: tree picker, `REGION_PICKER`: municipality or postcode suggest). Null means the system has no region parameter, so no picker is registered.
private
resolveRegionParameterField() : array{key: string, type: int}|null
IMPORTANT: on the add form no category is selected yet and parameterFormItems is empty.
Without the fallback to the parameter code list the picker would not be registered, the
standalone GET signal picker-…-suggest would end with 404 and the region could be chosen
only through the modal.
Return values
array{key: string, type: int}|nullsuggestCategories()
private
suggestCategories(string $query) : array<int, array{id: int, label: string}>
Parameters
- $query : string