diff --git a/src/Entity/Embargo.php b/src/Entity/Embargo.php index 89349b8..30b68e9 100644 --- a/src/Entity/Embargo.php +++ b/src/Entity/Embargo.php @@ -397,7 +397,10 @@ public function getCacheMaxAge() { * {@inheritdoc} */ public function getCacheTags() { - $tags = Cache::mergeTags(parent::getCacheTags(), $this->getEmbargoedNode()->getCacheTags()); + $tags = parent::getCacheTags(); + if ($node = $this->getEmbargoedNode()) { + $tags = Cache::mergeTags($tags, $node->getCacheTags()); + } if ($this->getExemptIps()) { $tags = Cache::mergeTags($tags, $this->getExemptIps()->getCacheTags()); @@ -411,9 +414,11 @@ public function getCacheTags() { public function getCacheContexts() { $contexts = Cache::mergeContexts( parent::getCacheContexts(), - $this->getEmbargoedNode()->getCacheContexts(), ['user.embargo__has_exemption'], ); + if ($node = $this->getEmbargoedNode()) { + $contexts = Cache::mergeContexts($contexts, $node->getCacheContexts()); + } if ($this->getExemptIps()) { $contexts = Cache::mergeContexts($contexts, $this->getExemptIps()->getCacheContexts()); diff --git a/src/Plugin/search_api/processor/EmbargoJoinProcessor.php b/src/Plugin/search_api/processor/EmbargoJoinProcessor.php index 90f4cf0..4083457 100644 --- a/src/Plugin/search_api/processor/EmbargoJoinProcessor.php +++ b/src/Plugin/search_api/processor/EmbargoJoinProcessor.php @@ -218,6 +218,12 @@ protected function doAddNodeField(ItemInterface $item, EntityInterface $entity) */ protected function doAddEmbargoField(ItemInterface $item, EntityInterface $entity) : void { assert($entity instanceof EmbargoInterface); + + // Early return if there is no embargoed node. + if ($entity->getEmbargoedNode() === NULL) { + return; + } + $paths = match ($entity->getEmbargoType()) { EmbargoInterface::EMBARGO_TYPE_FILE => [static::EMBARGO_FIELD_FILE], EmbargoInterface::EMBARGO_TYPE_NODE => [static::EMBARGO_FIELD_NODE, static::EMBARGO_FIELD_FILE],