class PlaceholderGenerator implements PlaceholderGeneratorInterface (View source)

Turns a render array into a placeholder.

Properties

protected array $rendererConfig

The renderer configuration array.

Methods

__construct(array $renderer_config)

Constructs a new Placeholder service.

bool
canCreatePlaceholder(array $element)

Analyzes whether the given render array can be placeholdered.

bool
shouldAutomaticallyPlaceholder(array $element)

Whether the given render array should be automatically placeholdered.

array
createPlaceholder(array $element)

Turns the given element into a placeholder.

Details

__construct(array $renderer_config)

Constructs a new Placeholder service.

Parameters

array $renderer_config

The renderer configuration array.

bool canCreatePlaceholder(array $element)

Analyzes whether the given render array can be placeholdered.

Parameters

array $element

A render array. Its #lazy_builder and #create_placeholder properties are analyzed.

Return Value

bool

bool shouldAutomaticallyPlaceholder(array $element)

Whether the given render array should be automatically placeholdered.

The render array should be placeholdered if its cacheability either has a cache context with too high cardinality, a cache tag with a too high invalidation rate, or a max-age that is too low. Either of these would make caching ineffective, and thus we choose to placeholder instead.

Parameters

array $element

The render array whose cacheability to analyze.

Return Value

bool

Whether the given render array's cacheability meets the placeholdering conditions.

array createPlaceholder(array $element)

Turns the given element into a placeholder.

Placeholdering allows us to avoid "poor cacheability contamination": this maps the current render array to one that only has #markup and #attached, and #attached contains a placeholder with this element's prior cacheability metadata. In other words: this placeholder is perfectly cacheable, the placeholder replacement logic effectively cordons off poor cacheability.

Parameters

array $element

The render array to create a placeholder for.

Return Value

array

Render array with placeholder markup and the attached placeholder replacement metadata.