CoolCMS API

AssetRenderer extends CellRenderer
in package

Asset preview; the column value is an {@see Asset} entity (typically `Column::create('asset')->setProperty('asset')`; requires the `asset` include).

  • Image: thumb preview, otherwise the smallest variant (Asset::getThumbnailPath()).
  • Video with a poster: the poster image (Asset::getPosterPath()) plus a play icon.
  • Video without a poster: a FontAwesome icon (setVideoIcon()).
  • Empty or missing value: a placeholder FontAwesome icon (setEmptyIcon()), or nothing by default.

NOTE: the preview is rendered whenever the asset has a file. The server cannot reliably know whether the file exists on FTP (meta can be stale), so a broken image is replaced by a placeholder box by the client fallback in datagrid.js.

Table of Contents

Properties

$emptyIcon  : string|null
$height  : int
$videoIcon  : string

Methods

__construct()  : mixed
create()  : static
getTemplateName()  : string
Cell template name (`Cells/<type>.latte`).
prepare()  : array<string, mixed>
Variables for the cell template.
setEmptyIcon()  : static
FontAwesome icon class of the placeholder for an empty or missing value (null renders nothing).
setHeight()  : static
Preview height in px.
setVideoIcon()  : static
FontAwesome icon class for a video without a preview (poster).
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.

Properties

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>

setEmptyIcon()

FontAwesome icon class of the placeholder for an empty or missing value (null renders nothing).

public setEmptyIcon(string|null $emptyIcon) : static
Parameters
$emptyIcon : string|null
Return values
static

setHeight()

Preview height in px.

public setHeight(int $height) : static
Parameters
$height : int
Return values
static

setVideoIcon()

FontAwesome icon class for a video without a preview (poster).

public setVideoIcon(string $videoIcon) : static
Parameters
$videoIcon : 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
On this page

Search results