Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PlaceholderingRenderCache.php

function PlaceholderingRenderCache::set

Overrides RenderCache::set

File

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

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal