CategoryPickerTrait
Blog category picker with two uses: - {@see categoryPicker()} for repeated selection in a multiplier (article categories, many-to-many), - {@see categoryParentPicker()} for a single parent category field (self-reference that excludes the edited category and its whole subtree).
The label is the translated name in the current language. Offers a suggester and a modal with
the show grid :Admin:Blog:Category. Requires $this->categoryManager.
Table of Contents
Methods
- addCategoryControls() : void
- categoryParentPicker() : PickerConfig
- Builds the single-field parent category picker (self-reference), like {@see \App\UI\Admin\System\Presenters\Traits\Pickers\PagePickerTrait::pagePicker()}.
- categoryPicker() : PickerConfig
- categoryName() : string
- Category name in the current language (falls back to the first non-empty one).
- resolveCategoryLabel() : string|null
- suggestCategories() : array<int, array{id: int, label: string}>
- Suggests categories by a `LIKE` match on the name, optionally without the excluded node and its whole subtree (parent self-reference).
Methods
addCategoryControls()
protected
addCategoryControls(Container $parent[, string $targetField = 'categoryId' ][, string $displayField = 'category' ]) : void
Parameters
- $parent : Container
- $targetField : string = 'categoryId'
- $displayField : string = 'category'
categoryParentPicker()
Builds the single-field parent category picker (self-reference), like {@see \App\UI\Admin\System\Presenters\Traits\Pickers\PagePickerTrait::pagePicker()}.
protected
categoryParentPicker([string $formName = 'editForm' ][, string $targetField = 'parentId' ][, int|null $excludeId = null ][, int|null $excludeLft = null ][, int|null $excludeRgt = null ]) : PickerConfig
The edited category and its descendants cannot be its parent, so they are excluded from the
suggester (lft/rgt) and from the modal (pickerExclude plus the subtree bounds).
Parameters
- $formName : string = 'editForm'
- $targetField : string = 'parentId'
- $excludeId : int|null = null
-
id of the edited category (self-reference)
- $excludeLft : int|null = null
-
lftof the edited category (subtree exclusion) - $excludeRgt : int|null = null
-
rgtof the edited category (subtree exclusion)
Return values
PickerConfigcategoryPicker()
protected
categoryPicker([string $formName = 'editForm' ][, string|null $container = 'categories' ][, string $targetField = 'categoryId' ][, string $displayField = 'category' ]) : PickerConfig
Parameters
- $formName : string = 'editForm'
- $container : string|null = 'categories'
- $targetField : string = 'categoryId'
- $displayField : string = 'category'
Return values
PickerConfigcategoryName()
Category name in the current language (falls back to the first non-empty one).
private
categoryName(Category $category) : string
Parameters
- $category : Category
Return values
stringresolveCategoryLabel()
private
resolveCategoryLabel(int $id) : string|null
Parameters
- $id : int
Return values
string|nullsuggestCategories()
Suggests categories by a `LIKE` match on the name, optionally without the excluded node and its whole subtree (parent self-reference).
private
suggestCategories(string $query[, int|null $excludeId = null ][, int|null $excludeLft = null ][, int|null $excludeRgt = null ]) : array<int, array{id: int, label: string}>
Parameters
- $query : string
- $excludeId : int|null = null
- $excludeLft : int|null = null
- $excludeRgt : int|null = null