diff --git a/dgi_fixity.module b/dgi_fixity.module index a974756..8d5b84e 100644 --- a/dgi_fixity.module +++ b/dgi_fixity.module @@ -202,18 +202,16 @@ function dgi_fixity_file_delete(EntityInterface $entity) { * Implements hook_ENTITY_TYPE_revision_create(). */ function dgi_fixity_fixity_check_revision_create(EntityInterface $entity) { - Cache::invalidateTags([ - 'fixity_check:' . $entity->id() . ':revisions_list', - ]); + /** @var \Drupal\dgi_fixity\FixityCheckInterface $entity*/ + Cache::invalidateTags($entity->getAuditCacheTags()); } /** * Implements hook_ENTITY_TYPE_revision_delete(). */ function dgi_fixity_fixity_check_revision_delete(EntityInterface $entity) { - Cache::invalidateTags([ - 'fixity_check:' . $entity->id() . ':revisions_list', - ]); + /** @var \Drupal\dgi_fixity\FixityCheckInterface $entity*/ + Cache::invalidateTags($entity->getAuditCacheTags()); } /** diff --git a/src/Controller/FixityCheckController.php b/src/Controller/FixityCheckController.php index 1c3ec5c..768d753 100644 --- a/src/Controller/FixityCheckController.php +++ b/src/Controller/FixityCheckController.php @@ -211,10 +211,7 @@ class FixityCheckController extends ControllerBase { // Date displayed varies by timezone. 'timezone', ], - 'tags' => [ - // Invalidated by revision create/delete hooks. - 'fixity_check:' . $fixity_check->id() . ':revisions_list', - ], + 'tags' => $fixity_check->getAuditCacheTags(), 'bin' => 'render', ]; $this->renderer->addCacheableDependency($build, $fixity_check); diff --git a/src/Entity/FixityCheck.php b/src/Entity/FixityCheck.php index db521da..1c95791 100644 --- a/src/Entity/FixityCheck.php +++ b/src/Entity/FixityCheck.php @@ -321,6 +321,15 @@ class FixityCheck extends ContentEntityBase implements FixityCheckInterface { $file->label(); } + /** + * {@inheritdoc} + */ + public function getAuditCacheTags() { + return [ + 'fixity_check:' . $this->id() . ':revisions_list', + ]; + } + /** * Defines allowed states for AllowedValues constraints. * diff --git a/src/FixityCheckInterface.php b/src/FixityCheckInterface.php index b1c7f2d..aedd833 100644 --- a/src/FixityCheckInterface.php +++ b/src/FixityCheckInterface.php @@ -226,4 +226,12 @@ interface FixityCheckInterface extends ContentEntityInterface, RevisionableInter */ public function setQueued(int $queued): FixityCheckInterface; + /** + * The cache tags associated with the audit display of this entity. + * + * @return string[] + * The cache tags. + */ + public function getAuditCacheTags(); + }