From 58060c634bdbe5ae3123336afb34da79520c75a4 Mon Sep 17 00:00:00 2001 From: berliner Date: Mon, 9 Dec 2024 10:54:00 +0100 Subject: [PATCH] HPC-9966: Fix issues with element contexts on cluster pages --- .../src/Plugin/Block/Plan/PlanAttachmentMap.php | 8 +++++--- .../src/Plugin/Block/Plan/PlanEntityLogframe.php | 11 +++++++---- .../src/Plugin/Block/Plan/PlanHeadlineFigures.php | 3 ++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/html/modules/custom/ghi_blocks/src/Plugin/Block/Plan/PlanAttachmentMap.php b/html/modules/custom/ghi_blocks/src/Plugin/Block/Plan/PlanAttachmentMap.php index 2000a7132..f7a87748d 100644 --- a/html/modules/custom/ghi_blocks/src/Plugin/Block/Plan/PlanAttachmentMap.php +++ b/html/modules/custom/ghi_blocks/src/Plugin/Block/Plan/PlanAttachmentMap.php @@ -6,6 +6,7 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Markup; +use Drupal\ghi_base_objects\Entity\BaseObjectAwareEntityInterface; use Drupal\ghi_blocks\Interfaces\ConfigValidationInterface; use Drupal\ghi_blocks\Interfaces\MultiStepFormBlockInterface; use Drupal\ghi_blocks\Interfaces\OverrideDefaultTitleBlockInterface; @@ -1201,11 +1202,12 @@ private function getAttachmentSwitcher() { * An array with context data or query handlers. */ public function getBlockContext() { + $page_node = $this->getPageNode(); return [ - 'page_node' => $this->getPageNode(), + 'page_node' => $page_node, 'plan_object' => $this->getCurrentPlanObject(), - 'base_object' => $this->getCurrentBaseObject(), - 'context_node' => $this->getPageNode(), + 'base_object' => $this->getCurrentBaseObject($page_node instanceof BaseObjectAwareEntityInterface ? $page_node : NULL), + 'context_node' => $page_node, 'attachment_prototype' => $this->getAttachmentPrototype(), ]; } diff --git a/html/modules/custom/ghi_blocks/src/Plugin/Block/Plan/PlanEntityLogframe.php b/html/modules/custom/ghi_blocks/src/Plugin/Block/Plan/PlanEntityLogframe.php index 38053ca45..14c5be82d 100644 --- a/html/modules/custom/ghi_blocks/src/Plugin/Block/Plan/PlanEntityLogframe.php +++ b/html/modules/custom/ghi_blocks/src/Plugin/Block/Plan/PlanEntityLogframe.php @@ -7,6 +7,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Markup; use Drupal\Core\Security\TrustedCallbackInterface; +use Drupal\ghi_base_objects\Entity\BaseObjectAwareEntityInterface; use Drupal\ghi_blocks\Interfaces\ConfigValidationInterface; use Drupal\ghi_blocks\Interfaces\ConfigurableTableBlockInterface; use Drupal\ghi_blocks\Interfaces\CustomLinkBlockInterface; @@ -612,7 +613,8 @@ private function getEntityRefCodeOptions() { * An array of plan entity objects for the current context. */ private function getPlanEntities($entity_ref_code = NULL) { - $context_object = $this->getCurrentBaseObject(); + $page_node = $this->getPageNode(); + $context_object = $this->getCurrentBaseObject($page_node instanceof BaseObjectAwareEntityInterface ? $page_node : NULL); if ($entity_ref_code == 'PL' && $context_object instanceof Plan) { /** @var \Drupal\ghi_plans\Plugin\EndpointQuery\EntityQuery $query */ @@ -730,12 +732,13 @@ public function getBlockContext() { // This can be any parent node, e.g. SectionNode or PlanClusterNode. $base_entity = $this->getCurrentBaseEntity(); $section_node = $this->sectionManager->getCurrentSection($base_entity); + $page_node = $this->getPageNode(); return [ 'section_node' => $section_node, - 'page_node' => $this->getPageNode(), + 'page_node' => $page_node, 'plan_object' => $plan_object, - 'base_object' => $this->getCurrentBaseObject(), - 'context_node' => $this->getPageNode(), + 'base_object' => $this->getCurrentBaseObject($page_node instanceof BaseObjectAwareEntityInterface ? $page_node : NULL), + 'context_node' => $page_node, 'entities' => $plan_entities, 'entity_types' => $this->logframeManager->getEntityTypesFromPlanObject($plan_object), 'attachment_prototypes' => $this->getAttachmentPrototypes(), diff --git a/html/modules/custom/ghi_blocks/src/Plugin/Block/Plan/PlanHeadlineFigures.php b/html/modules/custom/ghi_blocks/src/Plugin/Block/Plan/PlanHeadlineFigures.php index d1129b222..82b176868 100644 --- a/html/modules/custom/ghi_blocks/src/Plugin/Block/Plan/PlanHeadlineFigures.php +++ b/html/modules/custom/ghi_blocks/src/Plugin/Block/Plan/PlanHeadlineFigures.php @@ -4,6 +4,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\ghi_base_objects\Entity\BaseObjectAwareEntityInterface; use Drupal\ghi_blocks\Interfaces\ConfigValidationInterface; use Drupal\ghi_blocks\Interfaces\ConfigurableTableBlockInterface; use Drupal\ghi_blocks\Interfaces\MultiStepFormBlockInterface; @@ -219,7 +220,7 @@ public function getBlockContext() { 'section_node' => $this->getCurrentBaseEntity(), 'page_node' => $page_node, 'plan_object' => $this->getCurrentPlanObject(), - 'base_object' => $this->getCurrentBaseObject(), + 'base_object' => $this->getCurrentBaseObject($page_node instanceof BaseObjectAwareEntityInterface ? $page_node : NULL), 'context_node' => $page_node, ]; }