From c104e45e706e123b1c14f158cd1f44fc56f02c7d Mon Sep 17 00:00:00 2001 From: J Hunt Date: Sat, 28 Sep 2024 06:11:14 +1200 Subject: [PATCH] Context condition for Parent node of node has term (#1053) Co-authored-by: Jonathan Hunt --- .../Condition/ParentNodeOfNodeHasTerm.php | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/Plugin/Condition/ParentNodeOfNodeHasTerm.php diff --git a/src/Plugin/Condition/ParentNodeOfNodeHasTerm.php b/src/Plugin/Condition/ParentNodeOfNodeHasTerm.php new file mode 100644 index 000000000..26a3a41da --- /dev/null +++ b/src/Plugin/Condition/ParentNodeOfNodeHasTerm.php @@ -0,0 +1,75 @@ +configuration['uri']) && !$this->isNegated()) { + return TRUE; + } + + $node = $this->getContextValue('node'); + if (!$node) { + return FALSE; + } + + $fields = [$this->utils::MEMBER_OF_FIELD]; + $parentIds = $this->utils->findAncestors($node, $fields, 1); + if (!$parentIds) { + return FALSE; + } + $result = 0; + foreach ($parentIds as $parentId) { + $parent = $this->entityTypeManager->getStorage('node')->load($parentId); + if ($parent) { + $parentResult = $this->evaluateEntity($parent); + $result = $result + (int) $parentResult; + } + } + return (boolean) $result; + } + + /** + * {@inheritdoc} + */ + public function summary() { + if (!empty($this->configuration['negate'])) { + return $this->t('The parent node is not associated with taxonomy term with uri @uri.', ['@uri' => $this->configuration['uri']]); + } + else { + return $this->t('The parent node is associated with taxonomy term with uri @uri.', ['@uri' => $this->configuration['uri']]); + } + } + +}