CoolCMS API

LinkListRenderer extends CellRenderer
in package

List of related records in one cell (0..N links). Unlike other renderers the column value is an array of entities, not a scalar; the text, tooltip and link parameters are resolved from each item, not from the row entity.

The data is filled in one batch query through DataGrid::setRowDecorator() into a #[Transient] property of the row entity (like ProductSet::$currentPrice), which avoids N+1 and a callback over the row.

IMPORTANT: the property must return a plain array, not a Doctrine Collection; ValueResolver reduces a collection at the end of the path to its first element, so only one item would be printed silently.

An item gets no link (only text) when no destination is set, when the grid is in picker mode or when a mapped parameter is missing; same guard as BaseColumn::setLink().

Table of Contents

Properties

$destination  : string|null
$emptyText  : string
$icon  : string
$iconConditionProperty  : string|null
$iconDestination  : string|null
$iconParams  : array<string, string>
$iconTitle  : string|null
$params  : array<string, string>
$target  : string|null
$textFallbackFormat  : string
$textFallbackProperty  : string|null
$textOptions  : array<int|string, string>
$textProperty  : string
$titleOptions  : array<int|string, string>
$titleProperty  : 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 of an item, e.g. `:Admin:Invoicer:Invoice:edit`; null means text only.
setEmptyText()  : static
Text of an empty cell (empty when not set).
setIcon()  : static
FontAwesome icon class, default `fa-solid fa-file-pdf`.
setIconLink()  : static
Second link of an item rendered as an icon, typically a file download while the text links to the edit (like {@see PdfDownloadRenderer}). `$conditionProperty` hides the icon while that property is empty (the PDF is not generated yet); without it the icon is always shown.
setIconTitle()  : static
Icon tooltip (title attribute).
setParams()  : static
setTarget()  : static
E.g. `_blank` to open in a new window.
setTextFallbackProperty()  : static
Fallback text when `textProperty` cannot give one: the value is missing or not in the code list (a deleted type). `$format` is the `sprintf` mask of the fallback value.
setTextProperty()  : static
Item property with the link text. With `$options` the value is translated through the code list (`value => text`, like {@see OptionRenderer}), typically when the cell should show a meaningful name, not a bare id.
setTitleProperty()  : static
Item tooltip. Without `$options` the property value is printed, with them it is translated through the code list (`value => text`, like {@see OptionRenderer}).
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.
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.
buildHref()  : string|null
buildIconHref()  : string|null
The icon is hidden while the condition property is empty (the file does not exist yet).
buildLink()  : string|null
buildText()  : string
Link text in three steps: code list, fallback property, raw value. The raw value is last (never an empty `<a>`); without a code list it is taken right away, otherwise a property with its own text would lose to the fallback.
buildTitle()  : string|null

Properties

$iconConditionProperty

protected string|null $iconConditionProperty = null

$iconParams

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

URL parameter => item property path

$params

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

URL parameter => item property path

$textFallbackProperty

protected string|null $textFallbackProperty = null

$textOptions

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

textProperty value => link text

$titleOptions

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

titleProperty value => tooltip text

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 of an item, e.g. `:Admin:Invoicer:Invoice:edit`; null means text only.

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

setEmptyText()

Text of an empty cell (empty when not set).

public setEmptyText(string $emptyText) : static
Parameters
$emptyText : string
Return values
static

setIcon()

FontAwesome icon class, default `fa-solid fa-file-pdf`.

public setIcon(string $icon) : static
Parameters
$icon : string
Return values
static

Second link of an item rendered as an icon, typically a file download while the text links to the edit (like {@see PdfDownloadRenderer}). `$conditionProperty` hides the icon while that property is empty (the PDF is not generated yet); without it the icon is always shown.

public setIconLink(string|null $destination[, array<string, string> $params = ['id' => 'id'] ][, string|null $conditionProperty = null ]) : static

A null $destination turns the icon off.

Parameters
$destination : string|null
$params : array<string, string> = ['id' => 'id']

URL parameter => item property path

$conditionProperty : string|null = null
Return values
static

setIconTitle()

Icon tooltip (title attribute).

public setIconTitle(string|null $title) : static
Parameters
$title : string|null
Return values
static

setParams()

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

URL parameter => item 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

setTextFallbackProperty()

Fallback text when `textProperty` cannot give one: the value is missing or not in the code list (a deleted type). `$format` is the `sprintf` mask of the fallback value.

public setTextFallbackProperty(string|null $property[, string $format = '%s' ]) : static
Parameters
$property : string|null
$format : string = '%s'
Return values
static

setTextProperty()

Item property with the link text. With `$options` the value is translated through the code list (`value => text`, like {@see OptionRenderer}), typically when the cell should show a meaningful name, not a bare id.

public setTextProperty(string $property[, array<int|string, string> $options = [] ]) : static
Parameters
$property : string
$options : array<int|string, string> = []
Return values
static

setTitleProperty()

Item tooltip. Without `$options` the property value is printed, with them it is translated through the code list (`value => text`, like {@see OptionRenderer}).

public setTitleProperty(string|null $property[, array<int|string, string> $options = [] ]) : static
Parameters
$property : string|null
$options : array<int|string, string> = []
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

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

buildIconHref()

The icon is hidden while the condition property is empty (the file does not exist yet).

private buildIconHref(object $item, DataGrid $grid) : string|null
Parameters
$item : object
$grid : DataGrid
Return values
string|null
private buildLink(string|null $destination, array<string, string> $params, object $item, DataGrid $grid) : string|null
Parameters
$destination : string|null
$params : array<string, string>
$item : object
$grid : DataGrid
Return values
string|null

buildText()

Link text in three steps: code list, fallback property, raw value. The raw value is last (never an empty `<a>`); without a code list it is taken right away, otherwise a property with its own text would lose to the fallback.

private buildText(object $item) : string
Parameters
$item : object
Return values
string

buildTitle()

private buildTitle(object $item) : string|null
Parameters
$item : object
Return values
string|null
On this page

Search results