Browse Source

Node has Parent context does not explicitly check if the field exists. (#1019)

* Check that the field exists on node

* Early exit with disabled check
2.x
Akanksha Singh 4 months ago committed by GitHub
parent
commit
da47bcfb08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      src/IslandoraContextManager.php
  2. 6
      src/Plugin/Condition/NodeHasParent.php

2
src/IslandoraContextManager.php

@ -37,7 +37,7 @@ class IslandoraContextManager extends ContextManager {
}
/** @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;
}
}

6
src/Plugin/Condition/NodeHasParent.php

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

Loading…
Cancel
Save