/** * {@inheritdoc} */ public function render() { $rows = !empty($this->view->result) || $this->view->style_plugin->evenEmpty() ? $this->view->style_plugin->render($this->view->result) : array(); $element = array('#theme' => $this->themeFunctions(), '#view' => $this->view, '#pre_render' => [[$this, 'elementPreRender']], '#rows' => $rows, '#attached' => &$this->view->element['#attached'], '#cache' => &$this->view->element['#cache'], '#post_render_cache' => &$this->view->element['#post_render_cache']); if (!isset($element['#cache'])) { $element['#cache'] = []; } $element['#cache'] += ['tags' => []]; // If the output is a render array, add cache tags, regardless of whether // caching is enabled or not; cache tags must always be set. $element['#cache']['tags'] = Cache::mergeTags($element['#cache']['tags'], $this->view->getCacheTags()); return $element; }
/** * Applies the cacheability of the current display to the given render array. * * @param array $element * The render array with updated cacheability metadata. */ protected function applyDisplayCachablityMetadata(array &$element) { /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */ $cache = $this->getPlugin('cache'); (new CacheableMetadata())->setCacheTags(Cache::mergeTags($this->view->getCacheTags(), isset($this->display['cache_metadata']['tags']) ? $this->display['cache_metadata']['tags'] : []))->setCacheContexts(isset($this->display['cache_metadata']['contexts']) ? $this->display['cache_metadata']['contexts'] : [])->setCacheMaxAge(Cache::mergeMaxAges($cache->getCacheMaxAge(), isset($this->display['cache_metadata']['max-age']) ? $this->display['cache_metadata']['max-age'] : Cache::PERMANENT))->merge(CacheableMetadata::createFromRenderArray($element))->applyTo($element); }
/** * {@inheritdoc} */ protected function calculateXmlCacheTags() { // Pull the tags directly out of the view object. return $this->view->getCacheTags(); }