CoolCMS API

AssetPlaceholderHelper
in package

FinalYes

Placeholder image for an asset whose file cannot be loaded; the single source of truth for {@see \App\UI\Front\System\Components\AssetRendererComponent\AssetRenderer} and {@see \App\UI\Front\System\Components\GalleryComponent\Traits\InitTrait}.

Main case: the asset is in the (shared) DB, but the file exists only on the dev server and the local machine lacks it; without this the list would show a broken icon in its place.

A static helper (not a service) because entities and traits without DI call it; it builds on ThemeHelper and AssetPathResolver.

Table of Contents

Constants

IMAGE  : string = 'assets/imgs/placeholder-image.svg'
Placeholder images in the active theme (see `assets/imgs/`).
VIDEO  : string = 'assets/imgs/placeholder-video.svg'

Methods

exists()  : bool
Whether the file belonging to the public URL exists on disk.
resolve()  : string
URL to render: the original if the file exists, otherwise the placeholder.
url()  : string
Public URL of the placeholder image in the active theme.
__construct()  : mixed

Constants

IMAGE

Placeholder images in the active theme (see `assets/imgs/`).

private string IMAGE = 'assets/imgs/placeholder-image.svg'

Methods

exists()

Whether the file belonging to the public URL exists on disk.

public static exists(string|null $publicUrl) : bool

Fail-soft: when the path cannot be derived (AssetPathResolver without init(), empty URL), it returns true so the image is rendered and any error is handled by the client fallback (asset-fallback.js). An image that really exists is never hidden by this check.

Parameters
$publicUrl : string|null
Return values
bool

resolve()

URL to render: the original if the file exists, otherwise the placeholder.

public static resolve(string|null $publicUrl[, bool $video = false ]) : string

To tell whether it is a substitute, call exists() separately.

Parameters
$publicUrl : string|null
$video : bool = false
Return values
string

url()

Public URL of the placeholder image in the active theme.

public static url([bool $video = false ]) : string
Parameters
$video : bool = false
Return values
string
On this page

Search results