CoolCMS API

CategoryPickerTrait

Company category picker with two uses.

  • categoryPicker(): repeated selection in a Multiplier (reference categories, many-to-many).
  • categoryParentPicker(): single parent-category field (self-reference; excludes the edited category and its whole subtree).

The label is the translated name in the current language. Suggest plus modal with the show grid :Admin:Company:Category. Requires $this->categoryManager.

Table of Contents

Methods

addCategoryControls()  : void
Adds the category picker controls (hidden id and text label) to a Multiplier row.
categoryParentPicker()  : PickerConfig
Builds the parent-category picker (single field, self-reference).
categoryPicker()  : PickerConfig
categoryName()  : string
Returns the category name in the current language, falling back to the first non-empty one.
resolveCategoryLabel()  : string|null
suggestCategories()  : array<int, array{id: int, label: string}>
Suggests categories by `LIKE` on the name in the current language, optionally excluding a node and its subtree.

Methods

addCategoryControls()

Adds the category picker controls (hidden id and text label) to a Multiplier row.

protected addCategoryControls(Container $parent[, string $targetField = 'categoryId' ][, string $displayField = 'category' ]) : void
Parameters
$parent : Container
$targetField : string = 'categoryId'
$displayField : string = 'category'

categoryParentPicker()

Builds the parent-category picker (single field, self-reference).

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 the parent, so they are excluded from the suggest (lft/rgt) and from the modal (pickerExclude plus subtree bounds).

Parameters
$formName : string = 'editForm'
$targetField : string = 'parentId'
$excludeId : int|null = null

id of the edited category

$excludeLft : int|null = null

lft of the edited category (subtree exclusion)

$excludeRgt : int|null = null

rgt of the edited category (subtree exclusion)

Return values
PickerConfig

categoryPicker()

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
PickerConfig

categoryName()

Returns the category name in the current language, falling back to the first non-empty one.

private categoryName(Category $category) : string
Parameters
$category : Category
Return values
string

resolveCategoryLabel()

private resolveCategoryLabel(int $id) : string|null
Parameters
$id : int
Return values
string|null

suggestCategories()

Suggests categories by `LIKE` on the name in the current language, optionally excluding a node and its subtree.

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
Return values
array<int, array{id: int, label: string}>
On this page

Search results