CoolCMS API

OptionsSyncTrait uses trait:short

Synchronizes the options of a parameter from `meta['options']` in `ParameterManager::afterSave` (Bazaar, Comcat and Eshop; the module names its tables, see {@see ParameterTablesTrait}).

Options are child parameters (parent_id to the parameter, level = 2) in a nested set, so the sync is an id-stable upsert: existing optionId = UPDATE, new = INSERT + lft/rgt via service->insertTreeNode, removed = service->deleteTreeNode.

IMPORTANT: no delete-all + insert (unlike rules): option_id is referenced externally (stored item values, ParameterRuleTarget.option_id/ParameterRuleConditionValue.option_id with ON DELETE CASCADE), so a new id would break the references.

Raw DBAL writes in the same connection/transaction as service->save() (via $this->em), without detached-entity / UoW complications; lft/rgt are handled by service->insertTreeNode.

Edit only: on insert the parent has no lft/rgt yet (the insert gate runs after afterSave), so a child would be placed outside the parent. The admin form hides the options editor for a new parameter ("save first, then add options").

Deletion is hard (deleteTreeNode removes the row and closes the lft/rgt gap; the FK option_id ON DELETE CASCADE removes linked rules). To deactivate without deleting, use the active checkbox on the option.

Table of Contents

Properties

$em  : EntityManagerInterface
$service  : Service<string|int, BaseEntity>

Methods

parameterTablePrefix()  : string
Module part of the parameter table names: `'bazaar'`, `'comcat'` or `'eshop'`.
normalizeOptionsMeta()  : array<int, array{optionId: int, active: bool, default: bool, searchDefault: bool, texts: array}>
optionTreeService()  : TreeServiceInterface
Options are nodes of the parameter tree, so the parameter service is a tree service (lft/rgt).
parameterSqlName()  : string
`cms_mod_<module>_<name>`: a parameter table, or a FK column named after one.
syncOptions()  : void
upsertOptionTexts()  : void
Writes the option translations; a translation row exists only when the name is not empty.

Properties

Methods

parameterTablePrefix()

Module part of the parameter table names: `'bazaar'`, `'comcat'` or `'eshop'`.

protected abstract parameterTablePrefix() : string
Return values
string

normalizeOptionsMeta()

private normalizeOptionsMeta(mixed $raw) : array<int, array{optionId: int, active: bool, default: bool, searchDefault: bool, texts: array}>
Parameters
$raw : mixed
Return values
array<int, array{optionId: int, active: bool, default: bool, searchDefault: bool, texts: array}>

parameterSqlName()

`cms_mod_<module>_<name>`: a parameter table, or a FK column named after one.

private parameterSqlName(string $name) : string
Parameters
$name : string
Return values
string

upsertOptionTexts()

Writes the option translations; a translation row exists only when the name is not empty.

private upsertOptionTexts(Connection $connection, int $optionId, array<int, array{name: string, label: ?string}> $texts) : void

IMPORTANT: a row with name = '' would override the main-language fallback on a foreign-language version and the option would render without a name (a missing row behaves correctly). So an empty name creates no row and deletes an existing one: "admin cleared the English name" must mean "fall back", not "show nothing".

Parameters
$connection : Connection
$optionId : int
$texts : array<int, array{name: string, label: ?string}>
On this page

Search results