function PlaceholderingRenderCache::set

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/PlaceholderingRenderCache.php \Drupal\Core\Render\PlaceholderingRenderCache::set()
  2. 8.9.x core/lib/Drupal/Core/Render/PlaceholderingRenderCache.php \Drupal\Core\Render\PlaceholderingRenderCache::set()
  3. 11.x core/lib/Drupal/Core/Render/PlaceholderingRenderCache.php \Drupal\Core\Render\PlaceholderingRenderCache::set()

Overrides RenderCache::set

File

core/lib/Drupal/Core/Render/PlaceholderingRenderCache.php, line 126

Class

PlaceholderingRenderCache
Adds automatic placeholdering to the RenderCache.

Namespace

Drupal\Core\Render

Code

public function set(array &$elements, array $pre_bubbling_elements) {
    $result = parent::set($elements, $pre_bubbling_elements);
    // Writes to the render cache are disabled on uncacheable HTTP requests, to
    // prevent very low hit rate items from being written. If we're not writing
    // to the cache, there's also no benefit to placeholdering either.
    if (!$this->requestStack
        ->getCurrentRequest()
        ->isMethodCacheable()) {
        return FALSE;
    }
    if ($this->placeholderGenerator
        ->canCreatePlaceholder($pre_bubbling_elements) && $this->placeholderGenerator
        ->shouldAutomaticallyPlaceholder($elements)) {
        // Overwrite $elements with a placeholder. The Renderer (which called this
        // method) will update the context with the bubbleable metadata of the
        // overwritten $elements.
        $elements = $this->createPlaceholderAndRemember($this->getCacheableRenderArray($elements), $pre_bubbling_elements);
    }
    return $result;
}

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