DisplayRuleListTrait
Lists the unified pool of display rules for the "Display rules" tab.
Shared by Parameter and ParameterGroup and by Bazaar, Comcat and Eshop. Applying a rule to a target
is not done here: it is the staged CheckboxList displayRules on editForm, written through
AbstractParameterRuleManager::syncDisplayTargets() only when the parameter or group
is saved. This trait provides a readable rule summary, a "used elsewhere?" flag (stricter
delete confirm) and deleting a rule from the pool (signal deleteDisplayRule!, destructive
because the FK cascade removes the rule everywhere).
The presenter provides parameterRuleManager(), parameterManager(), operatorsDomain() and
displayRulesDomain() through abstract getters (Core must not import a module entity, see
AbstractParameterRuleManager), plus the inherited $translator, currentLangId(),
flashMessage() and redirect() from BasePresenter.
Table of Contents
Properties
- $displayRuleOptionNameCache : array<int, string>
- Option (child parameter) names by id for the rule summaries of one render.
Methods
- handleDeleteDisplayRule() : void
- Deletes a rule from the pool (the FK cascade removes its conditions, values, sources and targets everywhere), then redirects back.
- addDisplayRuleControl() : void
- Adds the staged `CheckboxList displayRules` (the whole rule pool) to the form; default = rules currently applied to the target.
- buildDisplayRulePool() : array<int, array{ruleId: int, summary: string, isShared: bool}>
- Builds the list rows for the whole rule pool: condition summary and whether the rule is used elsewhere too.
- displayRulesDomain() : string
- Translation domain of the shared "Display rules" component (`admin.bazaar.components.displayRules` / `admin.comcat.components.displayRules`).
- operatorsDomain() : string
- Translation domain of operator texts (`admin.bazaar.operators` / `admin.comcat.operators`).
- parameterManager() : Manager
- parameterRuleManager() : AbstractParameterRuleManager
- requireRuleHostEditPrivilege() : void
- IMPORTANT: host `edit` gate for managing the global rule pool; call it as the first statement.
- syncDisplayRuleControl() : void
- Writes the staged rule selection (form `displayRules`) into the targets of the given target.
- displayRuleName() : string
- Returns the parameter name in the current language (falls back to the first non-empty one).
- displayRuleOperatorLabel() : string
- Returns the operator (validator) label for the rule summary.
- displayRuleOptionNameById() : string
- Returns the option (child parameter) name by id.
- displayRuleSharedBeyond() : bool
- Returns whether the rule has a target outside this display target (stricter delete confirm).
- displayRuleSummary() : string
- Summarizes the rule conditions as "<source> <operator> <values>", joined with " + ".
Properties
$displayRuleOptionNameCache
Option (child parameter) names by id for the rule summaries of one render.
private
array<int, string>
$displayRuleOptionNameCache
= []
Methods
handleDeleteDisplayRule()
Deletes a rule from the pool (the FK cascade removes its conditions, values, sources and targets everywhere), then redirects back.
public
handleDeleteDisplayRule(int $ruleId) : void
Parameters
- $ruleId : int
Attributes
- #[Requires]
- $methods: 'POST'
addDisplayRuleControl()
Adds the staged `CheckboxList displayRules` (the whole rule pool) to the form; default = rules currently applied to the target.
protected
addDisplayRuleControl(Form $form, string $targetColumn, int $targetId) : void
setDefaultValue() is a no-op on submit (the submitted values win) and applies on GET or
redraw, so the list shows the DB state (a just-added rule is unchecked). Writing to the
targets is done by syncDisplayRuleControl() on save. Only for an existing target
($targetId > 0).
Parameters
- $form : Form
- $targetColumn : string
- $targetId : int
buildDisplayRulePool()
Builds the list rows for the whole rule pool: condition summary and whether the rule is used elsewhere too.
protected
buildDisplayRulePool(string $targetColumn, int $targetId) : array<int, array{ruleId: int, summary: string, isShared: bool}>
The "applied" checkmark lives in the form CheckboxList displayRules (default = rules currently applied).
Parameters
- $targetColumn : string
- $targetId : int
Return values
array<int, array{ruleId: int, summary: string, isShared: bool}>displayRulesDomain()
Translation domain of the shared "Display rules" component (`admin.bazaar.components.displayRules` / `admin.comcat.components.displayRules`).
protected
abstract displayRulesDomain() : string
Return values
stringoperatorsDomain()
Translation domain of operator texts (`admin.bazaar.operators` / `admin.comcat.operators`).
protected
abstract operatorsDomain() : string
Return values
stringparameterManager()
protected
abstract parameterManager() : Manager
Return values
ManagerparameterRuleManager()
protected
abstract parameterRuleManager() : AbstractParameterRuleManager
Return values
AbstractParameterRuleManagerrequireRuleHostEditPrivilege()
IMPORTANT: host `edit` gate for managing the global rule pool; call it as the first statement.
protected
requireRuleHostEditPrivilege() : void
Rules are a pool shared by the whole module on purpose, so the link between ruleId and the
edited target is not verified, only the host privilege :Admin:<Module>:Parameter:edit or
:Admin:<Module>:ParameterGroup:edit. The key comes from getName(), the presenter the
signal runs over. Signals and rule components can be invoked over any action of the
presenter (including show), so the gate of the edit action does not cover them.
syncDisplayRuleControl()
Writes the staged rule selection (form `displayRules`) into the targets of the given target.
protected
syncDisplayRuleControl(ArrayHash<string|int, mixed> $values, string $targetColumn, int $targetId) : void
Call it only after the parameter or group was saved successfully; that is why the changes take effect only after the whole parameter is saved.
Parameters
- $values : ArrayHash<string|int, mixed>
- $targetColumn : string
- $targetId : int
displayRuleName()
Returns the parameter name in the current language (falls back to the first non-empty one).
private
displayRuleName(ParameterInterface $parameter) : string
Parameters
- $parameter : ParameterInterface
Return values
stringdisplayRuleOperatorLabel()
Returns the operator (validator) label for the rule summary.
private
displayRuleOperatorLabel(string $validator) : string
Comparison operators are shown as math symbols (more compact: "Price >= 5000" instead of a
"Minimum" text); MIN/MAX are inclusive bounds, hence the symbols for greater-or-equal
and less-or-equal, not strict ones. Other operators (length, contains, filled, regular
expression) have no readable symbol and stay as the operators-domain text shared with the
rule editor.
Parameters
- $validator : string
Return values
stringdisplayRuleOptionNameById()
Returns the option (child parameter) name by id.
private
displayRuleOptionNameById(int $optionId) : string
Fallback for displayRuleSummary() when the hydrator does not load the 3-level relation
conditionsCollection.valuesCollection.option (the relation stays null while the mirror
column option_id is filled). Lazily cached across the rules of one render.
Parameters
- $optionId : int
Return values
stringdisplayRuleSharedBeyond()
Returns whether the rule has a target outside this display target (stricter delete confirm).
private
displayRuleSharedBeyond(AdminParameterRuleInterface $rule, string $targetColumn, int $targetId) : bool
Parameters
- $rule : AdminParameterRuleInterface
- $targetColumn : string
- $targetId : int
Return values
booldisplayRuleSummary()
Summarizes the rule conditions as "<source> <operator> <values>", joined with " + ".
private
displayRuleSummary(AdminParameterRuleInterface $rule) : string
Parameters
- $rule : AdminParameterRuleInterface