From 63d01787881f92ee482a4d79673c1e98ee132498 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 9 May 2024 11:51:55 -0300 Subject: [PATCH] Adjust caching for embargo and related access control. --- src/Access/EmbargoAccessCheck.php | 4 ++++ src/Entity/Embargo.php | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Access/EmbargoAccessCheck.php b/src/Access/EmbargoAccessCheck.php index e643958..3e6dcf0 100644 --- a/src/Access/EmbargoAccessCheck.php +++ b/src/Access/EmbargoAccessCheck.php @@ -74,6 +74,10 @@ public function access(EntityInterface $entity, AccountInterface $user) { )->render() ); array_map([$state, 'addCacheableDependency'], $embargoes); + + $type = $this->entityTypeManager->getDefinition('embargo'); + $state->addCacheTags($type->getListCacheTags()) + ->addCacheContexts($type->getListCacheContexts()); return $state; } diff --git a/src/Entity/Embargo.php b/src/Entity/Embargo.php index 1201540..21d6bdd 100644 --- a/src/Entity/Embargo.php +++ b/src/Entity/Embargo.php @@ -42,7 +42,8 @@ * "html" = "Drupal\Core\Entity\Routing\AdminHtmlRouteProvider" * }, * }, - * list_cache_tags = { "node_list", "media_list", "file_list" }, + * list_cache_contexts = { "ip.embargo_range", "user" }, + * list_cache_tags = { "embargo_list" }, * base_table = "embargo", * admin_permission = "administer embargo", * entity_keys = { @@ -450,4 +451,18 @@ public function ipIsExempt(string $ip): bool { return $exempt_ips && $exempt_ips->withinRanges($ip); } + /** + * {@inheritdoc} + */ + protected function getListCacheTagsToInvalidate() : array { + return array_merge( + parent::getListCacheTagsToInvalidate(), + [ + 'node_list', + 'media_list', + 'file_list', + ] + ); + } + }