core/lib/Drupal/Core/Entity/EntityFieldManager.php | 14 ++++++-------- core/lib/Drupal/Core/Entity/EntityTypeManager.php | 1 + .../Discovery/ContainerDerivativeDiscoveryDecorator.php | 13 ++++++++----- .../block_content/src/Plugin/Derivative/BlockContent.php | 12 ++++++------ .../src/Plugin/Derivative/ExtraFieldBlockDeriver.php | 12 ++++++------ .../src/Plugin/Derivative/FieldBlockDeriver.php | 12 ++++++------ .../system/src/Plugin/Derivative/SystemMenuBlock.php | 12 ++++++------ core/modules/views/src/Plugin/Derivative/ViewsBlock.php | 10 ++++++---- .../src/Plugin/Derivative/ViewsExposedFilterBlock.php | 12 ++++++------ 9 files changed, 51 insertions(+), 47 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/EntityFieldManager.php b/core/lib/Drupal/Core/Entity/EntityFieldManager.php index 72b84cc..71f49db 100644 --- a/core/lib/Drupal/Core/Entity/EntityFieldManager.php +++ b/core/lib/Drupal/Core/Entity/EntityFieldManager.php @@ -172,7 +172,7 @@ public function getBaseFieldDefinitions($entity_type_id) { else { // Rebuild the definitions and put it into the cache. $this->baseFieldDefinitions[$entity_type_id] = $this->buildBaseFieldDefinitions($entity_type_id); - $this->cacheSet($cid, $this->baseFieldDefinitions[$entity_type_id], Cache::PERMANENT, ['entity_types', 'entity_field_info']); + $this->cacheSet($cid, $this->baseFieldDefinitions[$entity_type_id], Cache::PERMANENT, Cache::mergeTags($this->entityTypeManager->getCacheTags(), $this->getCacheTags())); } } return $this->baseFieldDefinitions[$entity_type_id]; @@ -330,7 +330,7 @@ public function getFieldDefinitions($entity_type_id, $bundle) { else { // Rebuild the definitions and put it into the cache. $bundle_field_definitions = $this->buildBundleFieldDefinitions($entity_type_id, $bundle, $base_field_definitions); - $this->cacheSet($cid, $bundle_field_definitions, Cache::PERMANENT, ['entity_types', 'entity_field_info']); + $this->cacheSet($cid, $bundle_field_definitions, Cache::PERMANENT, Cache::mergeTags($this->entityTypeManager->getCacheTags(), $this->getCacheTags())); } // Field definitions consist of the bundle specific overrides and the // base fields, merge them together. Use array_replace() to replace base @@ -438,7 +438,7 @@ public function getFieldStorageDefinitions($entity_type_id) { else { // Rebuild the definitions and put it into the cache. $field_storage_definitions = $this->buildFieldStorageDefinitions($entity_type_id); - $this->cacheSet($cid, $field_storage_definitions, Cache::PERMANENT, ['entity_types', 'entity_field_info']); + $this->cacheSet($cid, $field_storage_definitions, Cache::PERMANENT, Cache::mergeTags($this->entityTypeManager->getCacheTags(), $this->getCacheTags())); } $this->fieldStorageDefinitions[$entity_type_id] += $field_storage_definitions; } @@ -500,7 +500,7 @@ public function getFieldMap() { } } - $this->cacheSet($cid, $this->fieldMap, Cache::PERMANENT, ['entity_types', 'entity_field_info']); + $this->cacheSet($cid, $this->fieldMap, Cache::PERMANENT, Cache::mergeTags($this->entityTypeManager->getCacheTags(), $this->getCacheTags())); } } return $this->fieldMap; @@ -573,7 +573,7 @@ public function clearCachedFieldDefinitions() { $this->fieldMapByFieldType = []; $this->entityDisplayRepository->clearDisplayModeInfo(); $this->extraFields = []; - Cache::invalidateTags(['entity_field_info']); + Cache::invalidateTags($this->getCacheTags()); // The typed data manager statically caches prototype objects with injected // definitions, clear those as well. $this->typedDataManager->clearCachedDefinitions(); @@ -620,9 +620,7 @@ public function getExtraFields($entity_type_id, $bundle) { // Store in the 'static' and persistent caches. $this->extraFields[$entity_type_id][$bundle] = $info; - $this->cacheSet($cache_id, $info, Cache::PERMANENT, [ - 'entity_field_info', - ]); + $this->cacheSet($cache_id, $info, Cache::PERMANENT, $this->getCacheTags()); return $this->extraFields[$entity_type_id][$bundle]; } diff --git a/core/lib/Drupal/Core/Entity/EntityTypeManager.php b/core/lib/Drupal/Core/Entity/EntityTypeManager.php index 9d7fdc5..e49f0a0 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeManager.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeManager.php @@ -4,6 +4,7 @@ use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; use Drupal\Component\Plugin\Exception\PluginNotFoundException; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\Entity\Exception\InvalidLinkTemplateException; diff --git a/core/lib/Drupal/Core/Plugin/Discovery/ContainerDerivativeDiscoveryDecorator.php b/core/lib/Drupal/Core/Plugin/Discovery/ContainerDerivativeDiscoveryDecorator.php index 009b01a..3eeac62 100644 --- a/core/lib/Drupal/Core/Plugin/Discovery/ContainerDerivativeDiscoveryDecorator.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/ContainerDerivativeDiscoveryDecorator.php @@ -4,17 +4,18 @@ use Drupal\Component\Plugin\Derivative\DeriverInterface; use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator; -use Drupal\Core\Cache\RefinableCacheableDependencyInterface; -use Drupal\Core\Cache\RefinableCacheableDependencyTrait; +use Drupal\Core\Cache\CacheableDependencyInterface; +use Drupal\Core\Cache\CacheableDependencyTrait; +use Drupal\Core\Cache\CacheableMetadata; /** * Injects dependencies into derivers if they use ContainerDeriverInterface. * * @see \Drupal\Core\Plugin\Discovery\ContainerDeriverInterface */ -class ContainerDerivativeDiscoveryDecorator extends DerivativeDiscoveryDecorator implements RefinableCacheableDependencyInterface { +class ContainerDerivativeDiscoveryDecorator extends DerivativeDiscoveryDecorator implements CacheableDependencyInterface { - use RefinableCacheableDependencyTrait; + use CacheableDependencyTrait; /** * {@inheritdoc} @@ -41,7 +42,9 @@ protected function getDeriver($base_plugin_id, $base_definition) { * {@inheritdoc} */ protected function processDeriver(DeriverInterface $deriver) { - $this->addCacheableDependency($deriver); + $existing_cacheability = CacheableMetadata::createFromObject($this); + $additional_cacheability = CacheableMetadata::createFromObject($deriver); + $this->setCacheability($existing_cacheability->merge($additional_cacheability)); } } diff --git a/core/modules/block_content/src/Plugin/Derivative/BlockContent.php b/core/modules/block_content/src/Plugin/Derivative/BlockContent.php index c3fa04d..18c0ca1 100644 --- a/core/modules/block_content/src/Plugin/Derivative/BlockContent.php +++ b/core/modules/block_content/src/Plugin/Derivative/BlockContent.php @@ -3,8 +3,8 @@ namespace Drupal\block_content\Plugin\Derivative; use Drupal\Component\Plugin\Derivative\DeriverBase; -use Drupal\Core\Cache\RefinableCacheableDependencyInterface; -use Drupal\Core\Cache\RefinableCacheableDependencyTrait; +use Drupal\Core\Cache\CacheableDependencyInterface; +use Drupal\Core\Cache\CacheableDependencyTrait; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -12,9 +12,9 @@ /** * Retrieves block plugin definitions for all custom blocks. */ -class BlockContent extends DeriverBase implements ContainerDeriverInterface, RefinableCacheableDependencyInterface { +class BlockContent extends DeriverBase implements ContainerDeriverInterface, CacheableDependencyInterface { - use RefinableCacheableDependencyTrait; + use CacheableDependencyTrait; /** * The custom block storage. @@ -31,6 +31,8 @@ class BlockContent extends DeriverBase implements ContainerDeriverInterface, Ref */ public function __construct(EntityStorageInterface $block_content_storage) { $this->blockContentStorage = $block_content_storage; + + $this->cacheTags = $this->blockContentStorage->getEntityType()->getListCacheTags(); } /** @@ -47,8 +49,6 @@ public static function create(ContainerInterface $container, $base_plugin_id) { * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { - $this->addCacheTags($this->blockContentStorage->getEntityType()->getListCacheTags()); - $block_contents = $this->blockContentStorage->loadByProperties(['reusable' => TRUE]); // Reset the discovered definitions. $this->derivatives = []; diff --git a/core/modules/layout_builder/src/Plugin/Derivative/ExtraFieldBlockDeriver.php b/core/modules/layout_builder/src/Plugin/Derivative/ExtraFieldBlockDeriver.php index 65cd09a..dcd7682 100644 --- a/core/modules/layout_builder/src/Plugin/Derivative/ExtraFieldBlockDeriver.php +++ b/core/modules/layout_builder/src/Plugin/Derivative/ExtraFieldBlockDeriver.php @@ -4,8 +4,8 @@ use Drupal\Component\Plugin\Derivative\DeriverBase; use Drupal\Component\Plugin\PluginBase; -use Drupal\Core\Cache\RefinableCacheableDependencyInterface; -use Drupal\Core\Cache\RefinableCacheableDependencyTrait; +use Drupal\Core\Cache\CacheableDependencyInterface; +use Drupal\Core\Cache\CacheableDependencyTrait; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; @@ -23,9 +23,9 @@ * experimental modules and development releases of contributed modules. * See https://www.drupal.org/core/experimental for more information. */ -class ExtraFieldBlockDeriver extends DeriverBase implements ContainerDeriverInterface, RefinableCacheableDependencyInterface { +class ExtraFieldBlockDeriver extends DeriverBase implements ContainerDeriverInterface, CacheableDependencyInterface { - use RefinableCacheableDependencyTrait; + use CacheableDependencyTrait; use StringTranslationTrait; /** @@ -63,6 +63,8 @@ public function __construct(EntityFieldManagerInterface $entity_field_manager, E $this->entityFieldManager = $entity_field_manager; $this->entityTypeManager = $entity_type_manager; $this->entityTypeBundleInfo = $entity_type_bundle_info; + + $this->setCacheability($this->entityFieldManager); } /** @@ -80,8 +82,6 @@ public static function create(ContainerInterface $container, $base_plugin_id) { * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { - $this->addCacheableDependency($this->entityFieldManager); - foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { // Only process fieldable entity types. if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) { diff --git a/core/modules/layout_builder/src/Plugin/Derivative/FieldBlockDeriver.php b/core/modules/layout_builder/src/Plugin/Derivative/FieldBlockDeriver.php index 59fab75..9d5b2d5 100644 --- a/core/modules/layout_builder/src/Plugin/Derivative/FieldBlockDeriver.php +++ b/core/modules/layout_builder/src/Plugin/Derivative/FieldBlockDeriver.php @@ -4,8 +4,8 @@ use Drupal\Component\Plugin\Derivative\DeriverBase; use Drupal\Component\Plugin\PluginBase; -use Drupal\Core\Cache\RefinableCacheableDependencyInterface; -use Drupal\Core\Cache\RefinableCacheableDependencyTrait; +use Drupal\Core\Cache\CacheableDependencyInterface; +use Drupal\Core\Cache\CacheableDependencyTrait; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeRepositoryInterface; use Drupal\Core\Field\FieldConfigInterface; @@ -21,9 +21,9 @@ * * @internal */ -class FieldBlockDeriver extends DeriverBase implements ContainerDeriverInterface, RefinableCacheableDependencyInterface { +class FieldBlockDeriver extends DeriverBase implements ContainerDeriverInterface, CacheableDependencyInterface { - use RefinableCacheableDependencyTrait; + use CacheableDependencyTrait; use StringTranslationTrait; /** @@ -71,6 +71,8 @@ public function __construct(EntityTypeRepositoryInterface $entity_type_repositor $this->entityFieldManager = $entity_field_manager; $this->fieldTypeManager = $field_type_manager; $this->formatterManager = $formatter_manager; + + $this->setCacheability($this->entityFieldManager); } /** @@ -89,8 +91,6 @@ public static function create(ContainerInterface $container, $base_plugin_id) { * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { - $this->addCacheableDependency($this->entityFieldManager); - $entity_type_labels = $this->entityTypeRepository->getEntityTypeLabels(); foreach ($this->entityFieldManager->getFieldMap() as $entity_type_id => $entity_field_map) { foreach ($entity_field_map as $field_name => $field_info) { diff --git a/core/modules/system/src/Plugin/Derivative/SystemMenuBlock.php b/core/modules/system/src/Plugin/Derivative/SystemMenuBlock.php index b741cbc..90a45c2 100644 --- a/core/modules/system/src/Plugin/Derivative/SystemMenuBlock.php +++ b/core/modules/system/src/Plugin/Derivative/SystemMenuBlock.php @@ -3,8 +3,8 @@ namespace Drupal\system\Plugin\Derivative; use Drupal\Component\Plugin\Derivative\DeriverBase; -use Drupal\Core\Cache\RefinableCacheableDependencyInterface; -use Drupal\Core\Cache\RefinableCacheableDependencyTrait; +use Drupal\Core\Cache\CacheableDependencyInterface; +use Drupal\Core\Cache\CacheableDependencyTrait; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -14,9 +14,9 @@ * * @see \Drupal\system\Plugin\Block\SystemMenuBlock */ -class SystemMenuBlock extends DeriverBase implements ContainerDeriverInterface, RefinableCacheableDependencyInterface { +class SystemMenuBlock extends DeriverBase implements ContainerDeriverInterface, CacheableDependencyInterface { - use RefinableCacheableDependencyTrait; + use CacheableDependencyTrait; /** * The menu storage. @@ -33,6 +33,8 @@ class SystemMenuBlock extends DeriverBase implements ContainerDeriverInterface, */ public function __construct(EntityStorageInterface $menu_storage) { $this->menuStorage = $menu_storage; + + $this->cacheTags = $this->menuStorage->getEntityType()->getListCacheTags(); } /** @@ -48,8 +50,6 @@ public static function create(ContainerInterface $container, $base_plugin_id) { * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { - $this->addCacheTags($this->menuStorage->getEntityType()->getListCacheTags()); - foreach ($this->menuStorage->loadMultiple() as $menu => $entity) { $this->derivatives[$menu] = $base_plugin_definition; $this->derivatives[$menu]['admin_label'] = $entity->label(); diff --git a/core/modules/views/src/Plugin/Derivative/ViewsBlock.php b/core/modules/views/src/Plugin/Derivative/ViewsBlock.php index 60c78ff..2a2c000 100644 --- a/core/modules/views/src/Plugin/Derivative/ViewsBlock.php +++ b/core/modules/views/src/Plugin/Derivative/ViewsBlock.php @@ -2,6 +2,8 @@ namespace Drupal\views\Plugin\Derivative; +use Drupal\Core\Cache\CacheableDependencyInterface; +use Drupal\Core\Cache\CacheableDependencyTrait; use Drupal\Core\Cache\RefinableCacheableDependencyInterface; use Drupal\Core\Cache\RefinableCacheableDependencyTrait; use Drupal\Core\Entity\EntityStorageInterface; @@ -14,9 +16,9 @@ * * @see \Drupal\views\Plugin\Block\ViewsBlock */ -class ViewsBlock implements ContainerDeriverInterface, RefinableCacheableDependencyInterface { +class ViewsBlock implements ContainerDeriverInterface, CacheableDependencyInterface { - use RefinableCacheableDependencyTrait; + use CacheableDependencyTrait; /** * List of derivative definitions. @@ -60,6 +62,8 @@ public static function create(ContainerInterface $container, $base_plugin_id) { public function __construct($base_plugin_id, EntityStorageInterface $view_storage) { $this->basePluginId = $base_plugin_id; $this->viewStorage = $view_storage; + + $this->cacheTags = $this->viewStorage->getEntityType()->getListCacheTags(); } /** @@ -77,8 +81,6 @@ public function getDerivativeDefinition($derivative_id, $base_plugin_definition) * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { - $this->addCacheTags($this->viewStorage->getEntityType()->getListCacheTags()); - // Check all Views for block displays. foreach ($this->viewStorage->loadMultiple() as $view) { // Do not return results for disabled views. diff --git a/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php b/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php index a48b8f7..df511ed 100644 --- a/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php +++ b/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php @@ -2,8 +2,8 @@ namespace Drupal\views\Plugin\Derivative; -use Drupal\Core\Cache\RefinableCacheableDependencyInterface; -use Drupal\Core\Cache\RefinableCacheableDependencyTrait; +use Drupal\Core\Cache\CacheableDependencyInterface; +use Drupal\Core\Cache\CacheableDependencyTrait; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Drupal\Core\Entity\EntityStorageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -13,9 +13,9 @@ * * @see \Drupal\views\Plugin\Block\ViewsExposedFilterBlock */ -class ViewsExposedFilterBlock implements ContainerDeriverInterface, RefinableCacheableDependencyInterface { +class ViewsExposedFilterBlock implements ContainerDeriverInterface, CacheableDependencyInterface { - use RefinableCacheableDependencyTrait; + use CacheableDependencyTrait; /** * List of derivative definitions. @@ -49,6 +49,8 @@ class ViewsExposedFilterBlock implements ContainerDeriverInterface, RefinableCac public function __construct($base_plugin_id, EntityStorageInterface $view_storage) { $this->basePluginId = $base_plugin_id; $this->viewStorage = $view_storage; + + $this->cacheTags = $this->viewStorage->getEntityType()->getListCacheTags(); } /** @@ -76,8 +78,6 @@ public function getDerivativeDefinition($derivative_id, $base_plugin_definition) * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { - $this->addCacheTags($this->viewStorage->getEntityType()->getListCacheTags()); - // Check all Views for displays with an exposed filter block. foreach ($this->viewStorage->loadMultiple() as $view) { // Do not return results for disabled views.