From 3b710713a0fae15835bb0d6896d7b10a65370623 Mon Sep 17 00:00:00 2001
From: Willow Gillingham <willow@born-digital.com>
Date: Wed, 20 Sep 2023 11:07:37 -0400
Subject: [PATCH] check that the underlying entity has the parent reference
 field before trying to get() it

---
 src/Plugin/Condition/NodeHasParent.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/Plugin/Condition/NodeHasParent.php b/src/Plugin/Condition/NodeHasParent.php
index 5002707f..ed7ddfd4 100644
--- a/src/Plugin/Condition/NodeHasParent.php
+++ b/src/Plugin/Condition/NodeHasParent.php
@@ -137,9 +137,9 @@ class NodeHasParent extends ConditionPluginBase implements ContainerFactoryPlugi
    *   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'];
+      if ($entity->getEntityTypeID() == 'node' && $referenced_entity->getEntityTypeId() == 'node' && $entity->hasField($parent_reference_field)) {
         $field = $entity->get($parent_reference_field);
         if (!$field->isEmpty()) {
           $nids = $field->getValue();