interface PlaceholderGeneratorInterface

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/PlaceholderGeneratorInterface.php \Drupal\Core\Render\PlaceholderGeneratorInterface
  2. 8.9.x core/lib/Drupal/Core/Render/PlaceholderGeneratorInterface.php \Drupal\Core\Render\PlaceholderGeneratorInterface
  3. 10 core/lib/Drupal/Core/Render/PlaceholderGeneratorInterface.php \Drupal\Core\Render\PlaceholderGeneratorInterface

Defines an interface for turning a render array into a placeholder.

This encapsulates logic related to generating placeholders.

Makes it possible to determine whether a render array can be placeholdered (it can be reconstructed independently of the request context), whether a render array should be placeholdered (its cacheability meets the conditions), and to create a placeholder.

Hierarchy

Expanded class hierarchy of PlaceholderGeneratorInterface

All classes that implement PlaceholderGeneratorInterface

See also

\Drupal\Core\Render\RendererInterface

1 file declares its use of PlaceholderGeneratorInterface
FiberPlaceholderTest.php in core/modules/big_pipe/tests/src/Unit/Render/FiberPlaceholderTest.php

File

core/lib/Drupal/Core/Render/PlaceholderGeneratorInterface.php, line 17

Namespace

Drupal\Core\Render
View source
interface PlaceholderGeneratorInterface {
    
    /**
     * Analyzes whether the given render array can be placeholdered.
     *
     * @param array $element
     *   A render array. Its #lazy_builder and #create_placeholder properties are
     *   analyzed.
     *
     * @return bool
     */
    public function canCreatePlaceholder(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.
     *
     * @param array $element
     *   The render array whose cacheability to analyze.
     *
     * @return bool
     *   Whether the given render array's cacheability meets the placeholdering
     *   conditions.
     */
    public function shouldAutomaticallyPlaceholder(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.
     *
     * @param array $element
     *   The render array to create a placeholder for.
     *
     * @return array
     *   Render array with placeholder markup and the attached placeholder
     *   replacement metadata.
     */
    public function createPlaceholder(array $element);
    
    /**
     * Generates a placeholder HTML tag.
     *
     * @param string $tag
     *   The placeholder tag.
     * @param array $attributes
     *   An array of key-value pairs to use as tag attributes.
     *
     * @return string
     *   The HTML placeholder.
     */
    public static function createPlaceholderTag(string $tag, array $attributes) : string;

}

Members

Title Sort descending Modifiers Object type Summary Overrides
PlaceholderGeneratorInterface::canCreatePlaceholder public function Analyzes whether the given render array can be placeholdered. 1
PlaceholderGeneratorInterface::createPlaceholder public function Turns the given element into a placeholder. 1
PlaceholderGeneratorInterface::createPlaceholderTag public static function Generates a placeholder HTML tag. 1
PlaceholderGeneratorInterface::shouldAutomaticallyPlaceholder public function Whether the given render array should be automatically placeholdered. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.