CoolCMS API

LinkRenderer extends CellRenderer
in package

Renders the value as a link to a presenter action.

Link parameters are mapped from row properties: setParams(['id' => 'id']) fills the URL parameter id with the id property of the entity. The destination is normally the same for the whole column (setDestination()); when it differs per row, it is read from an entity property (setDestinationProperty()).

Table of Contents

Properties

$destination  : string
$destinationProperty  : string|null
$params  : array<string, string>
$target  : string|null
$textProperty  : string|null

Methods

__construct()  : mixed
create()  : static
getTemplateName()  : string
Cell template name (`Cells/<type>.latte`).
prepare()  : array<string, mixed>
Variables for the cell template.
setDestination()  : static
Nette destination, e.g. `:Admin:System:Page:edit`.
setDestinationProperty()  : static
Row property the destination is read from, for columns whose target depends on row data.
setParams()  : static
setTarget()  : static
E.g. `_blank` to open in a new window.
setTextProperty()  : static
Row property the link text is read from instead of the column value, for columns whose value is a bare id (sorting and filtering work on it) but the user should see a name.
toCsvValue()  : string
Plain text value of the cell for the CSV export (no HTML/JS); does not change the normal render. The default implementation looks for a text in the vars from {@see prepare()} (key `text`; true for {@see TextRenderer}, {@see ComputedRenderer}, {@see OptionRenderer}, {@see BadgeRenderer}, `Date*Renderer`) and falls back to {@see toString()}. Renderers without a text representation (bool, select, toggle) override it.
resolveDestination()  : string|null
Returns `null` when the row has no target; the cell is then rendered as plain text.
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

$destinationProperty

protected string|null $destinationProperty = null

$params

protected array<string, string> $params = []

URL parameter => property path

$textProperty

protected string|null $textProperty = null

Methods

create()

public static create() : static
Return values
static

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>

setDestination()

Nette destination, e.g. `:Admin:System:Page:edit`.

public setDestination(string $destination) : static
Parameters
$destination : string
Return values
static

setDestinationProperty()

Row property the destination is read from, for columns whose target depends on row data.

public setDestinationProperty(string|null $propertyPath) : static

The property is typically filled by DataGrid::setRowDecorator() into a #[Transient] field.

An empty value means the row has nowhere to link: plain text without <a> is rendered (as in picker mode), not a link to this.

Parameters
$propertyPath : string|null
Return values
static

setParams()

public setParams(array<string, string> $params) : static
Parameters
$params : array<string, string>

URL parameter => entity property path

Return values
static

setTarget()

E.g. `_blank` to open in a new window.

public setTarget(string|null $target) : static
Parameters
$target : string|null
Return values
static

setTextProperty()

Row property the link text is read from instead of the column value, for columns whose value is a bare id (sorting and filtering work on it) but the user should see a name.

public setTextProperty(string|null $propertyPath) : static

An empty property falls back to the column value.

Parameters
$propertyPath : string|null
Return values
static

toCsvValue()

Plain text value of the cell for the CSV export (no HTML/JS); does not change the normal render. The default implementation looks for a text in the vars from {@see prepare()} (key `text`; true for {@see TextRenderer}, {@see ComputedRenderer}, {@see OptionRenderer}, {@see BadgeRenderer}, `Date*Renderer`) and falls back to {@see toString()}. Renderers without a text representation (bool, select, toggle) override it.

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

resolveDestination()

Returns `null` when the row has no target; the cell is then rendered as plain text.

protected resolveDestination(object $entity) : string|null
Parameters
$entity : object
Return values
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