From e41f49470d13ec96cd1b87c3484e3e497c91977f Mon Sep 17 00:00:00 2001 From: Akanksha Date: Thu, 9 May 2024 18:02:43 -0300 Subject: [PATCH 1/2] Check that the field exists on node --- src/Plugin/Condition/NodeHasParent.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Plugin/Condition/NodeHasParent.php b/src/Plugin/Condition/NodeHasParent.php index f9ef0cbf5..813fd00b1 100644 --- a/src/Plugin/Condition/NodeHasParent.php +++ b/src/Plugin/Condition/NodeHasParent.php @@ -137,9 +137,11 @@ public function evaluate() { * TRUE if entity references the specified parent. */ protected function evaluateEntity(EntityInterface $entity) { + $parent_reference_field = $this->configuration['parent_reference_field']; foreach ($entity->referencedEntities() as $referenced_entity) { - if ($entity->getEntityTypeID() == 'node' && $referenced_entity->getEntityTypeId() == 'node') { - $parent_reference_field = $this->configuration['parent_reference_field']; + // Check whether the entity and the referenced entity are nodes. + // Also make sure that the field exists. + if ($entity->getEntityTypeID() == 'node' && $entity->hasField($parent_reference_field) && $referenced_entity->getEntityTypeId() == 'node') { $field = $entity->get($parent_reference_field); if (!$field->isEmpty()) { $nids = $field->getValue(); From c89223fe6d55551fe1da5be724f069dafc84b666 Mon Sep 17 00:00:00 2001 From: Akanksha Date: Thu, 9 May 2024 18:03:13 -0300 Subject: [PATCH 2/2] Early exit with disabled check --- src/IslandoraContextManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IslandoraContextManager.php b/src/IslandoraContextManager.php index 9fd93fbc2..ed6f74af9 100644 --- a/src/IslandoraContextManager.php +++ b/src/IslandoraContextManager.php @@ -37,7 +37,7 @@ public function evaluateContexts(array $provided = []) { } /** @var \Drupal\context\ContextInterface $context */ foreach ($this->getContexts() as $context) { - if ($this->evaluateContextConditions($context, $provided) && !$context->disabled()) { + if (!$context->disabled() && $this->evaluateContextConditions($context, $provided)) { $this->activeContexts[$context->id()] = $context; } }