You are here

public function DisplayPluginBase::calculateCacheMetadata in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::calculateCacheMetadata()

Calculates the display's cache metadata by inspecting each handler/plugin.

Return value

\Drupal\Core\Cache\CacheableMetadata The cache metadata.

Overrides DisplayPluginInterface::calculateCacheMetadata

1 call to DisplayPluginBase::calculateCacheMetadata()
DisplayPluginBase::getCacheMetadata in core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
Gets the cache metadata.

File

core/modules/views/src/Plugin/views/display/DisplayPluginBase.php, line 2270
Contains \Drupal\views\Plugin\views\display\DisplayPluginBase.

Class

DisplayPluginBase
Base class for views display plugins.

Namespace

Drupal\views\Plugin\views\display

Code

public function calculateCacheMetadata() {
  $cache_metadata = new CacheableMetadata();

  // Iterate over ordinary views plugins.
  foreach (Views::getPluginTypes('plugin') as $plugin_type) {
    $plugin = $this
      ->getPlugin($plugin_type);
    if ($plugin instanceof CacheableDependencyInterface) {
      $cache_metadata = $cache_metadata
        ->merge(CacheableMetadata::createFromObject($plugin));
    }
  }

  // Iterate over all handlers. Note that at least the argument handler will
  // need to ask all its subplugins.
  foreach (array_keys(Views::getHandlerTypes()) as $handler_type) {
    $handlers = $this
      ->getHandlers($handler_type);
    foreach ($handlers as $handler) {
      if ($handler instanceof CacheableDependencyInterface) {
        $cache_metadata = $cache_metadata
          ->merge(CacheableMetadata::createFromObject($handler));
      }
    }
  }

  /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache_plugin */
  if ($cache_plugin = $this
    ->getPlugin('cache')) {
    $cache_plugin
      ->alterCacheMetadata($cache_metadata);
  }
  return $cache_metadata;
}