Skip to content

Commit

Permalink
Node has Parent context does not explicitly check if the field exists. (
Browse files Browse the repository at this point in the history
#1019)

* Check that the field exists on node

* Early exit with disabled check
  • Loading branch information
bibliophileaxe authored May 16, 2024
1 parent 5e958a5 commit da47bcf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/IslandoraContextManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/Plugin/Condition/NodeHasParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit da47bcf

Please sign in to comment.