AddAdvertFormTrait
Two-step advert adding: - without `catId` in the URL: `CategorySelectForm` (tree selection with checkboxes) - with `catId[]` in the URL: `AdvertForm` for the chosen categories
TODO: extract the form factories from this trait into a separate CategorySelectFormComponent.
Table of Contents
Properties
- $catId : array<string|int, int>|null
- $categoryNodesCache : array<int, array<string, mixed>>|null
- $selectedCategoryList : array<string|int, Category>
Methods
- actionAdd() : void
- renderAdd() : void
- createComponentAddAdvertForm() : AdvertForm
- createComponentCategorySelectForm() : Form
- buildCategoryHierarchy() : array<int, array<string, mixed>>
- Builds the recursive category tree by `parentId`.
- buildCategoryNodes() : array<int, array<string, mixed>>
- categoryLabel() : string
- collectLeafItems() : array<int, string>
- Builds the flat list `{leafId => label}` for `addCheckboxList`; only leaf categories (without children) get a checkbox.
- getCategoryNodes() : array<int, array<string, mixed>>
- isCategoryStepCompleted() : bool
- loadCategoryTree() : array<string|int, Category>
- loadSelectedCategories() : array<string|int, Category>
Properties
$catId
public
array<string|int, int>|null
$catId
= null
ids of the categories chosen in step 1 (null = nothing chosen yet)
Attributes
- #[Persistent]
$categoryNodesCache
private
array<int, array<string, mixed>>|null
$categoryNodesCache
= null
lazily cached tree for the select step
$selectedCategoryList
private
array<string|int, Category>
$selectedCategoryList
= []
categories loaded in step 2 by $catId
Methods
actionAdd()
public
actionAdd() : void
renderAdd()
public
renderAdd() : void
createComponentAddAdvertForm()
protected
createComponentAddAdvertForm() : AdvertForm
Return values
AdvertFormcreateComponentCategorySelectForm()
protected
createComponentCategorySelectForm() : Form
Return values
FormbuildCategoryHierarchy()
Builds the recursive category tree by `parentId`.
private
buildCategoryHierarchy(array<string|int, Category> $flat) : array<int, array<string, mixed>>
Each node: ['id', 'category', 'depth', 'isLeaf', 'label', 'priceLabel', 'children'].
Parameters
- $flat : array<string|int, Category>
Return values
array<int, array<string, mixed>>buildCategoryNodes()
private
buildCategoryNodes(array<string|int, Category> $categories, array<int, array<string|int, Category>> $childrenByParent, int $depth, int|null $langId) : array<int, array<string, mixed>>
Parameters
- $categories : array<string|int, Category>
- $childrenByParent : array<int, array<string|int, Category>>
- $depth : int
- $langId : int|null
Return values
array<int, array<string, mixed>>categoryLabel()
private
categoryLabel(Category $category, int|null $langId) : string
Parameters
- $category : Category
- $langId : int|null
Return values
stringcollectLeafItems()
Builds the flat list `{leafId => label}` for `addCheckboxList`; only leaf categories (without children) get a checkbox.
private
collectLeafItems(array<string|int, mixed> $nodes) : array<int, string>
Parameters
- $nodes : array<string|int, mixed>
-
nodes
{id, label, isLeaf, children}(children have the same shape)
Return values
array<int, string>getCategoryNodes()
private
getCategoryNodes() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>isCategoryStepCompleted()
private
isCategoryStepCompleted() : bool
Return values
boolloadCategoryTree()
private
loadCategoryTree() : array<string|int, Category>
Return values
array<string|int, Category>loadSelectedCategories()
private
loadSelectedCategories(array<string|int, int> $ids) : array<string|int, Category>
Parameters
- $ids : array<string|int, int>