Browse Source

Check that the field exists on node

pull/1019/head
Akanksha 11 months ago
parent
commit
e41f49470d
  1. 6
      src/Plugin/Condition/NodeHasParent.php

6
src/Plugin/Condition/NodeHasParent.php

@ -137,9 +137,11 @@ class NodeHasParent extends ConditionPluginBase implements ContainerFactoryPlugi
* TRUE if entity references the specified parent. * TRUE if entity references the specified parent.
*/ */
protected function evaluateEntity(EntityInterface $entity) { protected function evaluateEntity(EntityInterface $entity) {
$parent_reference_field = $this->configuration['parent_reference_field'];
foreach ($entity->referencedEntities() as $referenced_entity) { foreach ($entity->referencedEntities() as $referenced_entity) {
if ($entity->getEntityTypeID() == 'node' && $referenced_entity->getEntityTypeId() == 'node') { // Check whether the entity and the referenced entity are nodes.
$parent_reference_field = $this->configuration['parent_reference_field']; // 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); $field = $entity->get($parent_reference_field);
if (!$field->isEmpty()) { if (!$field->isEmpty()) {
$nids = $field->getValue(); $nids = $field->getValue();

Loading…
Cancel
Save