function PlaceholderGenerator::shouldAutomaticallyPlaceholder

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

Overrides PlaceholderGeneratorInterface::shouldAutomaticallyPlaceholder

File

core/lib/Drupal/Core/Render/PlaceholderGenerator.php, line 45

Class

PlaceholderGenerator
Turns a render array into a placeholder.

Namespace

Drupal\Core\Render

Code

public function shouldAutomaticallyPlaceholder(array $element) {
    // Auto-placeholder if the max-age, cache context or cache tag is specified
    // in the auto-placeholder conditions in the 'renderer.config' container
    // parameter.
    $conditions = $this->rendererConfig['auto_placeholder_conditions'];
    if (isset($element['#cache']['max-age']) && $element['#cache']['max-age'] !== Cache::PERMANENT && $element['#cache']['max-age'] <= $conditions['max-age']) {
        return TRUE;
    }
    if (isset($element['#cache']['contexts']) && array_intersect($element['#cache']['contexts'], $conditions['contexts'])) {
        return TRUE;
    }
    if (isset($element['#cache']['tags']) && array_intersect($element['#cache']['tags'], $conditions['tags'])) {
        return TRUE;
    }
    return FALSE;
}

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