CoolCMS API

CategoryChildrenTrait uses trait:short, trait:short

Template data for a module's `CategoryChildrenList`: the direct children of the current category (roots when there is none) and the way one level up.

The module supplies only what really differs: its manager, entity and router translator, CategoryRailTrait::categoryRailHref() and categoryChildrenRootHref(). Rows are built by CategoryRailTrait, so the shared rail templates (Style_4, Style_6) work unchanged.

Table of Contents

Constants

CATEGORY_CHILDREN_STYLES  : array<string|int, mixed> = ['Style_1', 'Style_4', 'Style_6']
Flat list is the shared `Style_1`; the others are contextual rail styles.
CATEGORY_RAIL_STYLES  : array<string|int, mixed> = ['Style_2', 'Style_4', 'Style_5', 'Style_6']
Styles that can be drawn from the shared template.
CATEGORY_RAIL_TEMPLATE_DIR  : string = __DIR__ . '/../../../Base/Front/Components/Cate...
Shared templates of {@see CATEGORY_RAIL_STYLES} for all modules.
CHILDREN_NAVIGATION_TEMPLATE_DIR  : string = __DIR__ . '/../../../Base/Front/Components/Chil...
Shared templates (`Style_1`) for every module's children list.

Methods

buildCategoryRailParent()  : array{name: string, href: string}|null
Returns the way one level up: the first item of the strip when the current category has a parent.
buildCategoryRailRows()  : array<int, array{id: int|null, name: string, href: string, count: int|null, iconPath: string|null, asset: object|null, iconClass: string|null, active: bool, children: array}>
Converts tree nodes into plain arrays for the template.
categoryChildrenRootHref()  : string
Link to the listing without a category — target of the back link at root level.
categoryChildrenTemplateDir()  : string
categoryRailCount()  : int|null
Returns the item count of a category.
categoryRailHref()  : string
Returns the link to the list of the given category; the only thing a module implements itself.
categoryRailTemplateDir()  : string
Returns the directory to load the template from.
childrenNavigationTemplateDir()  : string
Module (or theme) copy of the template wins; otherwise the shared one.
loadChildrenNavigation()  : array{items: array, parent: object|null}
prepareCategoryChildren()  : void
prepareCategoryRail()  : void
Fills `$railRows` and `$railParent` for the shared templates.
categoryRailCurrentId()  : int|null
categoryRailIconPath()  : string|null
Returns the legacy icon path, or `null` when unusable.
categoryRailName()  : string
resolveCurrentCategory()  : object|null
The page's category, but only when it belongs to this module — a component placed on another module's page must not adopt that module's category.

Constants

CATEGORY_CHILDREN_STYLES

Flat list is the shared `Style_1`; the others are contextual rail styles.

private array<string|int, mixed> CATEGORY_CHILDREN_STYLES = ['Style_1', 'Style_4', 'Style_6']

CATEGORY_RAIL_STYLES

Styles that can be drawn from the shared template.

private array<string|int, mixed> CATEGORY_RAIL_STYLES = ['Style_2', 'Style_4', 'Style_5', 'Style_6']

CATEGORY_RAIL_TEMPLATE_DIR

Shared templates of {@see CATEGORY_RAIL_STYLES} for all modules.

private string CATEGORY_RAIL_TEMPLATE_DIR = __DIR__ . '/../../../Base/Front/Components/CategoryList'

CHILDREN_NAVIGATION_TEMPLATE_DIR

Shared templates (`Style_1`) for every module's children list.

private string CHILDREN_NAVIGATION_TEMPLATE_DIR = __DIR__ . '/../../../Base/Front/Components/ChildrenNavigation'

Methods

buildCategoryRailParent()

Returns the way one level up: the first item of the strip when the current category has a parent.

protected buildCategoryRailParent(mixed $parent) : array{name: string, href: string}|null
Parameters
$parent : mixed
Return values
array{name: string, href: string}|null —

null for a root category or a page outside categories; the item is then not rendered

buildCategoryRailRows()

Converts tree nodes into plain arrays for the template.

protected buildCategoryRailRows(array<string|int, mixed> $nodes[, int $childLimit = 0 ]) : array<int, array{id: int|null, name: string, href: string, count: int|null, iconPath: string|null, asset: object|null, iconClass: string|null, active: bool, children: array}>

NOTE: the name is neither trimmed nor escaped; striptags|trim stays in the template so the output is identical to the former per-module copies.

Parameters
$nodes : array<string|int, mixed>

nodes from TreeStructure::prepareForTemplate()

$childLimit : int = 0

how many children to list in a tile (0 = none, Style_4)

Return values
array<int, array{id: int|null, name: string, href: string, count: int|null, iconPath: string|null, asset: object|null, iconClass: string|null, active: bool, children: array}>

categoryChildrenRootHref()

Link to the listing without a category — target of the back link at root level.

protected abstract categoryChildrenRootHref() : string
Return values
string

categoryChildrenTemplateDir()

protected categoryChildrenTemplateDir(string $ownDir, string $style) : string
Parameters
$ownDir : string
$style : string
Return values
string

categoryRailCount()

Returns the item count of a category.

protected categoryRailCount(object $category) : int|null

Overridable hook; the default reads the denormalized column of Bazaar/Comcat. The shop category entity carries no product count, so ProductCategoryList overrides it with a subtree count. Blog and Discussion return null and the templates render no count.

Parameters
$category : object
Return values
int|null

categoryRailHref()

Returns the link to the list of the given category; the only thing a module implements itself.

protected abstract categoryRailHref(int $categoryId) : string

IMPORTANT: it is built via $this->getPresenter()->link(), not {plink} in the template, because a shared template cannot know the target. For a foreign page it needs slug with the ID of the target page ($this->template->targetSlug), otherwise the link is a 404.

Parameters
$categoryId : int
Return values
string

categoryRailTemplateDir()

Returns the directory to load the template from.

protected categoryRailTemplateDir(string $ownDir, string $style) : string

A module's own copy (also a theme-specific one) takes precedence: whoever needs to deviate puts the file back into their Templates/…. The lookup mirrors BaseComponent::setTemplateFile() and only the final fallback returns the shared directory:

  • Templates/<Theme>/<Variant>/<style>.latte is a copy for the current theme;
  • Templates/Default/<style>.latte is a module copy for all themes;
  • otherwise the shared template in Base/Front/Components/CategoryList.

IMPORTANT: the lookup must never glob across all themes of the module. A theme-specific copy of another theme would be picked up while rendering a different theme, and when Templates/Default lacks the style the template file does not exist, which is a 500 for every theme without its own copy. Without a theme (CLI, no presenter) step one is skipped.

Parameters
$ownDir : string
$style : string
Return values
string

childrenNavigationTemplateDir()

Module (or theme) copy of the template wins; otherwise the shared one.

protected childrenNavigationTemplateDir(string $ownDir, string $style) : string

Same lookup order as BaseComponent::setTemplateFile().

Parameters
$ownDir : string
$style : string
Return values
string

prepareCategoryRail()

Fills `$railRows` and `$railParent` for the shared templates.

protected prepareCategoryRail(string $style[, int|null $childLimit = null ]) : void

IMPORTANT: call it right before setTemplateFile(). Bazaar still filters $sortedItems (preferred categories) in between, so an earlier call would hand the tiles the unfiltered tree.

Style_4 and Style_6 take the children of the current category ($currentBranch), or the roots when there is no context. null and [] differ: null means "not in a category, show roots", an empty array means "in a leaf category, nothing to show"; hence ??, not ?:.

  • Style_2 is Style_5 (tiles, roots/sortedItems) without the children list (childLimit 0): a flatter signpost, not a group with subcategories.
  • Style_6 is Style_4 (contextual nodes plus the way back $railParent) with a different template (a row of links instead of a tile with an icon).

NOTE: Bazaar, Comcat, Discussion and Blog have their own Templates/Default/Style_2.latte (categoryRailTemplateDir() prefers the module copy), so the shared Style_2 serves only the shop until the others switch to it.

Parameters
$style : string
$childLimit : int|null = null

categoryRailCurrentId()

private categoryRailCurrentId() : int|null
Return values
int|null

categoryRailIconPath()

Returns the legacy icon path, or `null` when unusable.

private categoryRailIconPath(object $category) : string|null

IMPORTANT: getAssetPath() can return ".", a non-empty but unusable string; without this check <img src="."> renders a broken image. Entities without getAssetPath() (articles, discussions, shop) return null and are drawn through the asset renderer only.

Parameters
$category : object
Return values
string|null

categoryRailName()

private categoryRailName(object $category) : string
Parameters
$category : object
Return values
string

resolveCurrentCategory()

The page's category, but only when it belongs to this module — a component placed on another module's page must not adopt that module's category.

private resolveCurrentCategory(class-string $entityClass) : object|null
Parameters
$entityClass : class-string
Return values
object|null
On this page

Search results