You are here

public function PlaceholderGenerator::shouldAutomaticallyPlaceholder in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Render/PlaceholderGenerator.php \Drupal\Core\Render\PlaceholderGenerator::shouldAutomaticallyPlaceholder()

Whether the given render array should be automatically placeholdered.

Parameters

array $element: The render array whose cacheability to analyze.

Return value

bool Whether the given render array's cacheability meets the placeholdering conditions.

Overrides PlaceholderGeneratorInterface::shouldAutomaticallyPlaceholder

File

core/lib/Drupal/Core/Render/PlaceholderGenerator.php, line 51
Contains \Drupal\Core\Render\PlaceholderGenerator.

Class

PlaceholderGenerator
Turns a render array into a placeholder.

Namespace

Drupal\Core\Render

Code

public function shouldAutomaticallyPlaceholder(array $element) {
  $conditions = $this->rendererConfig['auto_placeholder_conditions'];

  // Auto-placeholder if max-age is at or below the configured threshold.
  if (isset($element['#cache']['max-age']) && $element['#cache']['max-age'] !== Cache::PERMANENT && $element['#cache']['max-age'] <= $conditions['max-age']) {
    return TRUE;
  }

  // Auto-placeholder if a high-cardinality cache context is set.
  if (isset($element['#cache']['contexts']) && array_intersect($element['#cache']['contexts'], $conditions['contexts'])) {
    return TRUE;
  }

  // Auto-placeholder if a high-invalidation frequency cache tag is set.
  if (isset($element['#cache']['tags']) && array_intersect($element['#cache']['tags'], $conditions['tags'])) {
    return TRUE;
  }
  return FALSE;
}