function PlaceholderingRenderCache::get

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

Overrides RenderCache::get

File

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

Class

PlaceholderingRenderCache
Adds automatic placeholdering to the RenderCache.

Namespace

Drupal\Core\Render

Code

public function get(array $elements) {
    // @todo remove this check when https://www.drupal.org/node/2367555 lands.
    if (!$this->requestStack
        ->getCurrentRequest()
        ->isMethodCacheable()) {
        return FALSE;
    }
    // When rendering placeholders, special case auto-placeholdered elements:
    // avoid retrieving them from cache again, or rendering them again.
    if (isset($elements['#create_placeholder']) && $elements['#create_placeholder'] === FALSE) {
        $cached_placeholder_result = $this->getFromPlaceholderResultsCache($elements);
        if ($cached_placeholder_result !== FALSE) {
            return $cached_placeholder_result;
        }
    }
    $cached_element = parent::get($elements);
    if ($cached_element === FALSE) {
        return FALSE;
    }
    else {
        if ($this->placeholderGenerator
            ->canCreatePlaceholder($elements) && $this->placeholderGenerator
            ->shouldAutomaticallyPlaceholder($cached_element)) {
            return $this->createPlaceholderAndRemember($cached_element, $elements);
        }
        return $cached_element;
    }
}

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