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
$options
protected
array<int|string, string>
$options
= []
value => label
$updateProperty
protected
string|null
$updateProperty
= null
$variants
protected
array<int|string, string>
$variants
= []
value => color role (success, danger, neutral)
Methods
__construct()
public
final __construct() : mixed
create()
public
static create() : static
Return values
staticgetOptions()
public
getOptions() : array<int|string, string>
Return values
array<int|string, string>getTemplateName()
Cell template name (`Cells/<type>.latte`).
public
getTemplateName() : string
Return values
stringgetUpdateProperty()
public
getUpdateProperty(BaseColumn $column) : string
Parameters
- $column : BaseColumn
Return values
stringprepare()
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
staticsetUpdateProperty()
Property (database column) the new value is saved to.
public
setUpdateProperty(string|null $updateProperty) : static
Parameters
- $updateProperty : string|null
Return values
staticsetVariants()
Color role per value (value => success, danger, neutral).
public
setVariants(array<int|string, string> $variants) : static
Parameters
- $variants : array<int|string, string>
Return values
staticsetYesNo()
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
statictoCsvValue()
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
stringbuildUpdateUrl()
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
stringcsvOptionLabel()
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
stringresolveOptionKey()
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|nulltoScalarValue()
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