diff --git a/src/Plugin/Condition/EntityBundle.php b/src/Plugin/Condition/EntityBundle.php index 57547f3..51a57b1 100644 --- a/src/Plugin/Condition/EntityBundle.php +++ b/src/Plugin/Condition/EntityBundle.php @@ -102,9 +102,17 @@ class EntityBundle extends ConditionPluginBase implements ConstraintConditionInt if (empty($this->configuration['bundles']) && !$this->isNegated()) { return TRUE; } + /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ $entity = $this->getContextValue($this->bundleOf->id()); - return !empty($this->configuration['bundles'][$entity->bundle()]); + + // For negated conditions we need to make sure we are actually on an entity + // page. We need to return false since our condition is negated. + if ($this->isNegated() && !$entity) { + return FALSE; + } + + return !$entity || !empty($this->configuration['bundles'][$entity->bundle()]); } /** diff --git a/src/Plugin/Deriver/EntityBundle.php b/src/Plugin/Deriver/EntityBundle.php index e947e04..9fd8898 100644 --- a/src/Plugin/Deriver/EntityBundle.php +++ b/src/Plugin/Deriver/EntityBundle.php @@ -18,7 +18,7 @@ class EntityBundle extends EntityDeriverBase { $this->derivatives[$entity_type_id] = $base_plugin_definition; $this->derivatives[$entity_type_id]['label'] = $this->getEntityBundleLabel($entity_type); $this->derivatives[$entity_type_id]['context_definitions'] = [ - "$entity_type_id" => new EntityContextDefinition('entity:' . $entity_type_id), + "$entity_type_id" => new EntityContextDefinition('entity:' . $entity_type_id, $this->getEntityBundleLabel($entity_type), FALSE), ]; } }