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
$destination
protected
string|null
$destination
= null
$emptyText
protected
string
$emptyText
= ''
$icon
protected
string
$icon
= 'fa-solid fa-file-pdf'
$iconConditionProperty
protected
string|null
$iconConditionProperty
= null
$iconDestination
protected
string|null
$iconDestination
= null
$iconParams
protected
array<string, string>
$iconParams
= []
URL parameter => item property path
$iconTitle
protected
string|null
$iconTitle
= null
$params
protected
array<string, string>
$params
= []
URL parameter => item property path
$target
protected
string|null
$target
= null
$textFallbackFormat
protected
string
$textFallbackFormat
= '%s'
$textFallbackProperty
protected
string|null
$textFallbackProperty
= null
$textOptions
protected
array<int|string, string>
$textOptions
= []
textProperty value => link text
$textProperty
protected
string
$textProperty
= 'id'
$titleOptions
protected
array<int|string, string>
$titleOptions
= []
titleProperty value => tooltip text
$titleProperty
protected
string|null
$titleProperty
= null
Methods
__construct()
public
final __construct() : mixed
create()
public
static create() : static
Return values
staticgetTemplateName()
Cell template name (`Cells/<type>.latte`).
public
getTemplateName() : string
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>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
staticsetEmptyText()
Text of an empty cell (empty when not set).
public
setEmptyText(string $emptyText) : static
Parameters
- $emptyText : string
Return values
staticsetIcon()
FontAwesome icon class, default `fa-solid fa-file-pdf`.
public
setIcon(string $icon) : static
Parameters
- $icon : string
Return values
staticsetIconLink()
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
staticsetIconTitle()
Icon tooltip (title attribute).
public
setIconTitle(string|null $title) : static
Parameters
- $title : string|null
Return values
staticsetParams()
public
setParams(array<string, string> $params) : static
Parameters
- $params : array<string, string>
-
URL parameter => item property path
Return values
staticsetTarget()
E.g. `_blank` to open in a new window.
public
setTarget(string|null $target) : static
Parameters
- $target : string|null
Return values
staticsetTextFallbackProperty()
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
staticsetTextProperty()
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
staticsetTitleProperty()
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
statictoCsvValue()
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
stringtoScalarValue()
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
stringbuildHref()
private
buildHref(object $item, DataGrid $grid) : string|null
Parameters
- $item : object
- $grid : DataGrid
Return values
string|nullbuildIconHref()
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|nullbuildLink()
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|nullbuildText()
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
stringbuildTitle()
private
buildTitle(object $item) : string|null
Parameters
- $item : object