Commit 5859ca2c authored by alexpott's avatar alexpott

Issue #2040135 by Wim Leers, Berdir: Caches dependent on simple config are...

Issue #2040135 by Wim Leers, Berdir: Caches dependent on simple config are only invalidated on form submissions
parent 2f628af6
...@@ -406,7 +406,7 @@ services: ...@@ -406,7 +406,7 @@ services:
arguments: ['@plugin.manager.menu.link'] arguments: ['@plugin.manager.menu.link']
menu.tree_storage: menu.tree_storage:
class: Drupal\Core\Menu\MenuTreeStorage class: Drupal\Core\Menu\MenuTreeStorage
arguments: ['@database', '@cache.menu', 'menu_tree'] arguments: ['@database', '@cache.menu', '@cache_tags.invalidator', 'menu_tree']
public: false # Private to plugin.manager.menu.link and menu.link_tree public: false # Private to plugin.manager.menu.link and menu.link_tree
tags: tags:
- { name: backend_overridable } - { name: backend_overridable }
......
...@@ -69,7 +69,7 @@ function system_list_reset() { ...@@ -69,7 +69,7 @@ function system_list_reset() {
// @todo Trigger an event upon module install/uninstall and theme // @todo Trigger an event upon module install/uninstall and theme
// enable/disable, and move this into an event subscriber. // enable/disable, and move this into an event subscriber.
// @see https://drupal.org/node/2206347 // @see https://drupal.org/node/2206347
Cache::invalidateTags(array('extension')); Cache::invalidateTags(['config:core.extension']);
} }
/** /**
......
...@@ -97,7 +97,7 @@ public function checkNamedRoute($route_name, array $parameters = array(), Accoun ...@@ -97,7 +97,7 @@ public function checkNamedRoute($route_name, array $parameters = array(), Accoun
} }
catch (RouteNotFoundException $e) { catch (RouteNotFoundException $e) {
// Cacheable until extensions change. // Cacheable until extensions change.
$result = AccessResult::forbidden()->addCacheTags(array('extension')); $result = AccessResult::forbidden()->addCacheTags(['config:core.extension']);
return $return_as_object ? $result : $result->isAllowed(); return $return_as_object ? $result : $result->isAllowed();
} }
catch (ParamNotConvertedException $e) { catch (ParamNotConvertedException $e) {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableInterface; use Drupal\Core\Cache\CacheableInterface;
use Drupal\Core\Config\ConfigBase;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
...@@ -360,6 +361,19 @@ public function cacheUntilEntityChanges(EntityInterface $entity) { ...@@ -360,6 +361,19 @@ public function cacheUntilEntityChanges(EntityInterface $entity) {
return $this; return $this;
} }
/**
* Convenience method, adds the configuration object's cache tag.
*
* @param \Drupal\Core\Config\ConfigBase $configuration
* The configuration object whose cache tag to set on the access result.
*
* @return $this
*/
public function cacheUntilConfigurationChanges(ConfigBase $configuration) {
$this->addCacheTags($configuration->getCacheTags());
return $this;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -81,14 +81,16 @@ public static function validateTags(array $tags) { ...@@ -81,14 +81,16 @@ public static function validateTags(array $tags) {
* A prefix string. * A prefix string.
* @param array $suffixes * @param array $suffixes
* An array of suffixes. Will be cast to strings. * An array of suffixes. Will be cast to strings.
* @param string $glue
* A string to be used as glue for concatenation. Defaults to a colon.
* *
* @return string[] * @return string[]
* An array of cache tags. * An array of cache tags.
*/ */
public static function buildTags($prefix, array $suffixes) { public static function buildTags($prefix, array $suffixes, $glue = ':') {
$tags = []; $tags = [];
foreach ($suffixes as $suffix) { foreach ($suffixes as $suffix) {
$tags[] = $prefix . ':' . $suffix; $tags[] = $prefix . $glue . $suffix;
} }
return $tags; return $tags;
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\Core\Config; namespace Drupal\Core\Config;
use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/** /**
...@@ -223,6 +224,9 @@ public function save() { ...@@ -223,6 +224,9 @@ public function save() {
} }
$this->storage->write($this->name, $this->data); $this->storage->write($this->name, $this->data);
if (!$this->isNew) {
Cache::invalidateTags($this->getCacheTags());
}
$this->isNew = FALSE; $this->isNew = FALSE;
$this->eventDispatcher->dispatch(ConfigEvents::SAVE, new ConfigCrudEvent($this)); $this->eventDispatcher->dispatch(ConfigEvents::SAVE, new ConfigCrudEvent($this));
$this->originalData = $this->data; $this->originalData = $this->data;
...@@ -238,6 +242,7 @@ public function save() { ...@@ -238,6 +242,7 @@ public function save() {
public function delete() { public function delete() {
$this->data = array(); $this->data = array();
$this->storage->delete($this->name); $this->storage->delete($this->name);
Cache::invalidateTags($this->getCacheTags());
$this->isNew = TRUE; $this->isNew = TRUE;
$this->resetOverriddenData(); $this->resetOverriddenData();
$this->eventDispatcher->dispatch(ConfigEvents::DELETE, new ConfigCrudEvent($this)); $this->eventDispatcher->dispatch(ConfigEvents::DELETE, new ConfigCrudEvent($this));
......
...@@ -262,4 +262,15 @@ public function merge(array $data_to_merge) { ...@@ -262,4 +262,15 @@ public function merge(array $data_to_merge) {
$this->setData(NestedArray::mergeDeepArray(array($this->data, $data_to_merge), TRUE)); $this->setData(NestedArray::mergeDeepArray(array($this->data, $data_to_merge), TRUE));
return $this; return $this;
} }
/**
* The unique cache tag associated with this configuration object.
*
* @return string[]
* An array of cache tags.
*/
public function getCacheTags() {
return ['config:' . $this->name];
}
} }
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\Core\Config; namespace Drupal\Core\Config;
use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
...@@ -218,6 +219,7 @@ public function reset($name = NULL) { ...@@ -218,6 +219,7 @@ public function reset($name = NULL) {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function rename($old_name, $new_name) { public function rename($old_name, $new_name) {
Cache::invalidateTags($this->get($old_name)->getCacheTags());
$this->storage->rename($old_name, $new_name); $this->storage->rename($old_name, $new_name);
// Clear out the static cache of any references to the old name. // Clear out the static cache of any references to the old name.
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
use Drupal\Core\Entity\Entity; use Drupal\Core\Entity\Entity;
use Drupal\Core\Config\ConfigDuplicateUUIDException; use Drupal\Core\Config\ConfigDuplicateUUIDException;
use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityWithPluginCollectionInterface; use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Plugin\PluginDependencyTrait; use Drupal\Core\Plugin\PluginDependencyTrait;
...@@ -371,6 +372,15 @@ public function link($text = NULL, $rel = 'edit-form', array $options = []) { ...@@ -371,6 +372,15 @@ public function link($text = NULL, $rel = 'edit-form', array $options = []) {
return parent::link($text, $rel, $options); return parent::link($text, $rel, $options);
} }
/**
* {@inheritdoc}
*/
public function getCacheTags() {
// Use cache tags that match the underlying config object's name.
// @see \Drupal\Core\Config\ConfigBase::getCacheTags()
return ['config:' . $this->getConfigDependencyName()];
}
/** /**
* Overrides \Drupal\Core\Entity\DependencyTrait:addDependency(). * Overrides \Drupal\Core\Entity\DependencyTrait:addDependency().
* *
...@@ -411,4 +421,24 @@ public function getConfigDependencyName() { ...@@ -411,4 +421,24 @@ public function getConfigDependencyName() {
public function onDependencyRemoval(array $dependencies) { public function onDependencyRemoval(array $dependencies) {
} }
/**
* {@inheritdoc}
*
* Override to never invalidate the entity's cache tag; the config system
* already invalidates it.
*/
protected function invalidateTagsOnSave($update) {
Cache::invalidateTags($this->getEntityType()->getListCacheTags());
}
/**
* {@inheritdoc}
*
* Override to never invalidate the individual entities' cache tags; the
* config system already invalidates them.
*/
protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities) {
Cache::invalidateTags($entity_type->getListCacheTags());
}
} }
...@@ -64,6 +64,12 @@ class ConfigEntityType extends EntityType { ...@@ -64,6 +64,12 @@ class ConfigEntityType extends EntityType {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function __construct($definition) { public function __construct($definition) {
// Ensure a default list cache tag is set; do this before calling the parent
// constructor, because we want "Configuration System style" cache tags.
if (empty($this->list_cache_tags)) {
$this->list_cache_tags = ['config:' . $definition['id'] . '_list'];
}
parent::__construct($definition); parent::__construct($definition);
// Always add a default 'uuid' key. // Always add a default 'uuid' key.
$this->entity_keys['uuid'] = 'uuid'; $this->entity_keys['uuid'] = 'uuid';
......
...@@ -66,16 +66,18 @@ abstract class StorableConfigBase extends ConfigBase { ...@@ -66,16 +66,18 @@ abstract class StorableConfigBase extends ConfigBase {
/** /**
* Saves the configuration object. * Saves the configuration object.
* *
* @return \Drupal\Core\Config\Config * Must invalidate the cache tags associated with the configuration object.
* The configuration object. *
* @return $this
*/ */
abstract public function save(); abstract public function save();
/** /**
* Deletes the configuration object. * Deletes the configuration object.
* *
* @return \Drupal\Core\Config\Config * Must invalidate the cache tags associated with the configuration object.
* The configuration object. *
* @return $this
*/ */
abstract public function delete(); abstract public function delete();
......
...@@ -407,7 +407,7 @@ public static function preDelete(EntityStorageInterface $storage, array $entitie ...@@ -407,7 +407,7 @@ public static function preDelete(EntityStorageInterface $storage, array $entitie
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function postDelete(EntityStorageInterface $storage, array $entities) { public static function postDelete(EntityStorageInterface $storage, array $entities) {
self::invalidateTagsOnDelete($storage->getEntityType(), $entities); static::invalidateTagsOnDelete($storage->getEntityType(), $entities);
} }
/** /**
......
...@@ -399,7 +399,7 @@ public function getTypedData(); ...@@ -399,7 +399,7 @@ public function getTypedData();
/** /**
* The unique cache tag associated with this entity. * The unique cache tag associated with this entity.
* *
* @return array * @return string[]
* An array of cache tags. * An array of cache tags.
*/ */
public function getCacheTags(); public function getCacheTags();
......
...@@ -125,7 +125,7 @@ public function getCurrentRouteMenuTreeParameters($menu_name) { ...@@ -125,7 +125,7 @@ public function getCurrentRouteMenuTreeParameters($menu_name) {
// expanded. // expanded.
->addExpandedParents($this->treeStorage->getExpanded($menu_name, $active_trail)); ->addExpandedParents($this->treeStorage->getExpanded($menu_name, $active_trail));
$this->cache->set($cid, $parameters, CacheBackendInterface::CACHE_PERMANENT, array('menu:' . $menu_name)); $this->cache->set($cid, $parameters, CacheBackendInterface::CACHE_PERMANENT, array('config:system.menu.' . $menu_name));
} }
$this->cachedCurrentRouteParameters[$menu_name] = $parameters; $this->cachedCurrentRouteParameters[$menu_name] = $parameters;
} }
...@@ -255,7 +255,7 @@ public function build(array $tree, $level = 0) { ...@@ -255,7 +255,7 @@ public function build(array $tree, $level = 0) {
$build['#theme'] = 'menu__' . strtr($menu_name, '-', '_'); $build['#theme'] = 'menu__' . strtr($menu_name, '-', '_');
$build['#items'] = $items; $build['#items'] = $items;
// Set cache tag. // Set cache tag.
$build['#cache']['tags'][] = 'menu:' . $menu_name; $build['#cache']['tags'][] = 'config:system.menu.' . $menu_name;
return $build; return $build;
} }
else { else {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
use Drupal\Component\Utility\UrlHelper; use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\Query\SelectInterface;
...@@ -41,6 +42,13 @@ class MenuTreeStorage implements MenuTreeStorageInterface { ...@@ -41,6 +42,13 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
*/ */
protected $menuCacheBackend; protected $menuCacheBackend;
/**
* The cache tags invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
*/
protected $cacheTagsInvalidator;
/** /**
* The database table name. * The database table name.
* *
...@@ -109,14 +117,17 @@ class MenuTreeStorage implements MenuTreeStorageInterface { ...@@ -109,14 +117,17 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
* A Database connection to use for reading and writing configuration data. * A Database connection to use for reading and writing configuration data.
* @param \Drupal\Core\Cache\CacheBackendInterface $menu_cache_backend * @param \Drupal\Core\Cache\CacheBackendInterface $menu_cache_backend
* Cache backend instance for the extracted tree data. * Cache backend instance for the extracted tree data.
* @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
* The cache tags invalidator.
* @param string $table * @param string $table
* A database table name to store configuration data in. * A database table name to store configuration data in.
* @param array $options * @param array $options
* (optional) Any additional database connection options to use in queries. * (optional) Any additional database connection options to use in queries.
*/ */
public function __construct(Connection $connection, CacheBackendInterface $menu_cache_backend, $table, array $options = array()) { public function __construct(Connection $connection, CacheBackendInterface $menu_cache_backend, CacheTagsInvalidatorInterface $cache_tags_invalidator, $table, array $options = array()) {
$this->connection = $connection; $this->connection = $connection;
$this->menuCacheBackend = $menu_cache_backend; $this->menuCacheBackend = $menu_cache_backend;
$this->cacheTagsInvalidator = $cache_tags_invalidator;
$this->table = $table; $this->table = $table;
$this->options = $options; $this->options = $options;
} }
...@@ -180,8 +191,8 @@ public function rebuild(array $definitions) { ...@@ -180,8 +191,8 @@ public function rebuild(array $definitions) {
$this->resetDefinitions(); $this->resetDefinitions();
$affected_menus = $this->getMenuNames() + $before_menus; $affected_menus = $this->getMenuNames() + $before_menus;
// Invalidate any cache tagged with any menu name. // Invalidate any cache tagged with any menu name.
$cache_tags = Cache::buildTags('menu', $affected_menus); $cache_tags = Cache::buildTags('config:system.menu', $affected_menus, '.');
Cache::invalidateTags($cache_tags); $this->cacheTagsInvalidator->invalidateTags($cache_tags);
$this->resetDefinitions(); $this->resetDefinitions();
// Every item in the cache bin should have one of the menu cache tags but it // Every item in the cache bin should have one of the menu cache tags but it
// is not guaranteed, so invalidate everything in the bin. // is not guaranteed, so invalidate everything in the bin.
...@@ -241,8 +252,8 @@ protected function safeExecuteSelect(SelectInterface $query) { ...@@ -241,8 +252,8 @@ protected function safeExecuteSelect(SelectInterface $query) {
public function save(array $link) { public function save(array $link) {
$affected_menus = $this->doSave($link); $affected_menus = $this->doSave($link);
$this->resetDefinitions(); $this->resetDefinitions();
$cache_tags = Cache::buildTags('menu', $affected_menus); $cache_tags = Cache::buildTags('config:system.menu', $affected_menus, '.');
Cache::invalidateTags($cache_tags); $this->cacheTagsInvalidator->invalidateTags($cache_tags);
return $affected_menus; return $affected_menus;
} }
...@@ -394,7 +405,7 @@ public function delete($id) { ...@@ -394,7 +405,7 @@ public function delete($id) {
$this->updateParentalStatus($item); $this->updateParentalStatus($item);
// Many children may have moved. // Many children may have moved.
$this->resetDefinitions(); $this->resetDefinitions();
Cache::invalidateTags(array('menu:' . $item['menu_name'])); $this->cacheTagsInvalidator->invalidateTags(['config:system.menu.' . $item['menu_name']]);
} }
} }
...@@ -823,7 +834,7 @@ public function loadTreeData($menu_name, MenuTreeParameters $parameters) { ...@@ -823,7 +834,7 @@ public function loadTreeData($menu_name, MenuTreeParameters $parameters) {
$data['tree'] = $this->doBuildTreeData($links, $parameters->activeTrail, $parameters->minDepth); $data['tree'] = $this->doBuildTreeData($links, $parameters->activeTrail, $parameters->minDepth);
$data['definitions'] = array(); $data['definitions'] = array();
$data['route_names'] = $this->collectRoutesAndDefinitions($data['tree'], $data['definitions']); $data['route_names'] = $this->collectRoutesAndDefinitions($data['tree'], $data['definitions']);
$this->menuCacheBackend->set($tree_cid, $data, Cache::PERMANENT, array('menu:' . $menu_name)); $this->menuCacheBackend->set($tree_cid, $data, Cache::PERMANENT, ['config:system.menu.' . $menu_name]);
// The definitions were already added to $this->definitions in // The definitions were already added to $this->definitions in
// $this->doBuildTreeData() // $this->doBuildTreeData()
unset($data['definitions']); unset($data['definitions']);
......
...@@ -143,6 +143,13 @@ public function saveOverride($id, array $definition) { ...@@ -143,6 +143,13 @@ public function saveOverride($id, array $definition) {
return array_keys($definition); return array_keys($definition);
} }
/**
* {@inheritdoc}
*/
public function getCacheTags() {
return $this->getConfig()->getCacheTags();
}
/** /**
* Encodes the ID by replacing dots with double underscores. * Encodes the ID by replacing dots with double underscores.
* *
......
...@@ -84,4 +84,12 @@ public function loadMultipleOverrides(array $ids); ...@@ -84,4 +84,12 @@ public function loadMultipleOverrides(array $ids);
*/ */
public function saveOverride($id, array $definition); public function saveOverride($id, array $definition);
/**
* The unique cache tag associated with this menu link override.
*
* @return string[]
* An array of cache tags.
*/
public function getCacheTags();
} }
...@@ -20,29 +20,11 @@ class Page extends RenderElement { ...@@ -20,29 +20,11 @@ class Page extends RenderElement {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getInfo() { public function getInfo() {
$class = get_class($this);
return array( return array(
'#show_messages' => TRUE, '#show_messages' => TRUE,
'#pre_render' => array(
array($class, 'preRenderPage'),
),
'#theme' => 'page', '#theme' => 'page',
'#title' => '', '#title' => '',
); );
} }
/**
* #pre_render callback for the page element type.
*
* @param array $element
* A structured array containing the page element type build properties.
*
* @return array
*/
public static function preRenderPage($element) {
$element['#cache']['tags'][] = 'theme:' . \Drupal::theme()->getActiveTheme()->getName();
$element['#cache']['tags'][] = 'theme_global_settings';
return $element;
}
} }
...@@ -42,8 +42,8 @@ public function __construct(ThemeHandlerInterface $theme_handler) { ...@@ -42,8 +42,8 @@ public function __construct(ThemeHandlerInterface $theme_handler) {
* The access result. * The access result.
*/ */
public function access($theme) { public function access($theme) {
// Cacheable until the theme is modified. // Cacheable until the theme settings are modified.
return AccessResult::allowedIf($this->checkAccess($theme))->addCacheTags(array('theme:' . $theme)); return AccessResult::allowedIf($this->checkAccess($theme))->addCacheTags(['config:' . $theme . '.settings']);
} }
/** /**
......
...@@ -46,4 +46,12 @@ public function __construct($theme) { ...@@ -46,4 +46,12 @@ public function __construct($theme) {
public function getTheme() { public function getTheme() {
return $this->theme; return $this->theme;
} }
/**
* {@inheritdoc}
*/
public function getCacheTags() {
return ['rendered'];
}
} }
...@@ -237,19 +237,6 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { ...@@ -237,19 +237,6 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
} }
} }
/**
* {@inheritdoc}
*
* Block configuration entities are a special case: one block entity stores
* the placement of one block in one theme. Changing these entities may affect
* any page that is rendered in a certain theme, even if the block doesn't
* appear there currently. Hence a block configuration entity must also return
* the associated theme's cache tag.
*/
public function getCacheTags() {
return Cache::mergeTags(parent::getCacheTags(), ['theme:' . $this->theme]);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
use Drupal\block\Event\BlockEvents; use Drupal\block\Event\BlockEvents;
use Drupal\Core\Block\MainContentBlockPluginInterface; use Drupal\Core\Block\MainContentBlockPluginInterface;
use Drupal\Core\Display\PageVariantInterface; use Drupal\Core\Display\PageVariantInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityViewBuilderInterface; use Drupal\Core\Entity\EntityViewBuilderInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Display\VariantBase; use Drupal\Core\Display\VariantBase;
...@@ -43,11 +44,11 @@ class BlockPageVariant extends VariantBase implements PageVariantInterface, Cont ...@@ -43,11 +44,11 @@ class BlockPageVariant extends VariantBase implements PageVariantInterface, Cont
protected $blockViewBuilder; protected $blockViewBuilder;
/** /**
* The current theme. * The Block entity type list cache tags.
* *
* @var string * @var string[]
*/ */
protected $theme; protected $blockListCacheTags;
/** /**
* The render array representing the main page content. * The render array representing the main page content.
...@@ -71,12 +72,15 @@ class BlockPageVariant extends VariantBase implements PageVariantInterface, Cont ...@@ -71,12 +72,15 @@ class BlockPageVariant extends VariantBase implements PageVariantInterface, Cont
* The block view builder. * The block view builder.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
* The event dispatcher. * The event dispatcher.
* @param string[] $block_list_cache_tags
* The Block entity type list cache tags.
*/ */
public function __construct(array $configuration, $plugin_id, $plugin_definition, BlockRepositoryInterface $block_repository, EntityViewBuilderInterface $block_view_builder, EventDispatcherInterface $dispatcher) { public function __construct(array $configuration, $plugin_id, $plugin_definition, BlockRepositoryInterface $block_repository, EntityViewBuilderInterface $block_view_builder, EventDispatcherInterface $dispatcher, array $block_list_cache_tags) {
parent::__construct($configuration, $plugin_id, $plugin_definition); parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->blockRepository = $block_repository; $this->blockRepository = $block_repository;
$this->blockViewBuilder = $block_view_builder; $this->blockViewBuilder = $block_view_builder;
$this->dispatcher = $dispatcher; $this->dispatcher = $dispatcher;
$this->blockListCacheTags = $block_list_cache_tags;
} }
/** /**
...@@ -89,7 +93,8 @@ public static function create(ContainerInterface $container, array $configuratio ...@@ -89,7 +93,8 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_definition, $plugin_definition,
$container->get('block.repository'), $container->get('block.repository'),
$container->get('entity.manager')->getViewBuilder('block'), $container->get('entity.manager')->getViewBuilder('block'),
$container->get('event_dispatcher') $container->get('event_dispatcher'),
$container->get('entity.manager')->getDefinition('block')->getListCacheTags()
); );
} }
...@@ -108,7 +113,11 @@ public function build() { ...@@ -108,7 +113,11 @@ public function build() {
// Track whether a block that shows the main content is displayed or not. // Track whether a block that shows the main content is displayed or not.
$main_content_block_displayed = FALSE; $main_content_block_displayed = FALSE;