CoolCMS API

RelationToggleRenderer extends ToggleRenderer
in package

Renders a toggle for a cell whose value lives in a related collection ({@see RelationColumn}), not in a row column.

Looks the same as ToggleRenderer (shares the toggle template) but writes elsewhere: instead of inlineUpdate! it links to the relationToggle! signal, which also carries scope (the relation identifier, e.g. the role id in the RBAC matrix) and delegates to RelationTogglable.

Table of Contents

Properties

$options  : array<int|string, string>
$updateProperty  : string|null
$variants  : array<int|string, string>

Methods

__construct()  : mixed
create()  : static
getOptions()  : array<int|string, string>
getTemplateName()  : string
Cell template name (`Cells/<type>.latte`).
getUpdateProperty()  : string
prepare()  : array<string, mixed>
Variables for the cell template.
setOptions()  : static
setUpdateProperty()  : static
Property (database column) the new value is saved to.
setVariants()  : static
Color role per value (value => success, danger, neutral).
setYesNo()  : static
Shortcut for the most common yes/no switch over a bool column.
toCsvValue()  : string
The `prepare()` vars have no `text` key (a switch has `label`/`variant`/`position`), so the CSV export uses the option label.
buildUpdateUrl()  : string
Builds the URL that switches to the next value: the default inline update (the `inlineUpdate!` signal calling `manager->updateColumns()` on the row column).
csvOptionLabel()  : string
Label of the current value for the CSV export. {@see SelectRenderer} / {@see ToggleRenderer} have no plain `text` key in the `prepare()` vars (options/current, label/variant for the switch UI), so their `toCsvValue()` uses this instead of the default from {@see CellRenderer}.
resolveOptionKey()  : int|string|null
Key in options matching the current value (compared as strings because of int vs. string keys), or null when the value is not among the options.
toScalarValue()  : mixed
Column value to a scalar comparable with the keys of `options` maps: a `BackedEnum` becomes its `value`, a pure enum its `name`, a bool 0/1. Other values pass unchanged.
toString()  : string
Column value (mixed) to text; non-stringable values give an empty string.

Properties

$variants

protected array<int|string, string> $variants = []

value => color role (success, danger, neutral)

Methods

create()

public static create() : static
Return values
static

getOptions()

public getOptions() : array<int|string, string>
Return values
array<int|string, string>

getTemplateName()

Cell template name (`Cells/<type>.latte`).

public getTemplateName() : string
Return values
string

prepare()

Variables for the cell template.

public prepare(mixed $value, object $entity, DataGrid $grid, BaseColumn $column) : array<string, mixed>
Parameters
$value : mixed
$entity : object
$grid : DataGrid
$column : BaseColumn
Return values
array<string, mixed>

setOptions()

public setOptions(array<int|string, string> $options) : static
Parameters
$options : array<int|string, string>

value => label

Return values
static

setUpdateProperty()

Property (database column) the new value is saved to.

public setUpdateProperty(string|null $updateProperty) : static
Parameters
$updateProperty : string|null
Return values
static

setVariants()

Color role per value (value => success, danger, neutral).

public setVariants(array<int|string, string> $variants) : static
Parameters
$variants : array<int|string, string>
Return values
static

setYesNo()

Shortcut for the most common yes/no switch over a bool column.

public setYesNo(string $yesLabel, string $noLabel) : static

The order (no, yes) sets the knob position: left is no, right is yes.

Parameters
$yesLabel : string
$noLabel : string
Return values
static

toCsvValue()

The `prepare()` vars have no `text` key (a switch has `label`/`variant`/`position`), so the CSV export uses the option label.

public toCsvValue(mixed $value, object $entity, DataGrid $grid, BaseColumn $column) : string
Parameters
$value : mixed
$entity : object
$grid : DataGrid
$column : BaseColumn
Return values
string

buildUpdateUrl()

Builds the URL that switches to the next value: the default inline update (the `inlineUpdate!` signal calling `manager->updateColumns()` on the row column).

protected buildUpdateUrl(DataGrid $grid, BaseColumn $column, object $entity, int|string $nextValue) : string

Subclasses (e.g. RelationToggleRenderer) override it with another signal.

Parameters
$grid : DataGrid
$column : BaseColumn
$entity : object
$nextValue : int|string
Return values
string

csvOptionLabel()

Label of the current value for the CSV export. {@see SelectRenderer} / {@see ToggleRenderer} have no plain `text` key in the `prepare()` vars (options/current, label/variant for the switch UI), so their `toCsvValue()` uses this instead of the default from {@see CellRenderer}.

protected csvOptionLabel(mixed $value) : string
Parameters
$value : mixed
Return values
string

resolveOptionKey()

Key in options matching the current value (compared as strings because of int vs. string keys), or null when the value is not among the options.

protected resolveOptionKey(mixed $value) : int|string|null
Parameters
$value : mixed
Return values
int|string|null

toScalarValue()

Column value to a scalar comparable with the keys of `options` maps: a `BackedEnum` becomes its `value`, a pure enum its `name`, a bool 0/1. Other values pass unchanged.

protected toScalarValue(mixed $value) : mixed

IMPORTANT: entities return an enum object for enum columns (typed property), so without this normalization the cell template receives an object and (string) $enum is a fatal error, not an empty output.

Parameters
$value : mixed

toString()

Column value (mixed) to text; non-stringable values give an empty string.

protected toString(mixed $value) : string

An enum prints its value/name; a bool keeps the (string) semantics (false is empty, not "0"), as the admin always printed it.

Parameters
$value : mixed
Return values
string
On this page

Search results