From f7fc037b438e02a770991f99b2a7a5dceb6557ff Mon Sep 17 00:00:00 2001 From: berliner Date: Tue, 21 Nov 2023 10:35:49 +0100 Subject: [PATCH] Prevent errors when importing page configuration for new homepage and errors when running bulk section creation --- .../custom/ghi_sections/src/SectionCreateBatch.php | 3 ++- .../modules/custom/hpc_common/src/Plugin/HPCBlockBase.php | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/html/modules/custom/ghi_sections/src/SectionCreateBatch.php b/html/modules/custom/ghi_sections/src/SectionCreateBatch.php index f00a896e3..bb2296a8e 100644 --- a/html/modules/custom/ghi_sections/src/SectionCreateBatch.php +++ b/html/modules/custom/ghi_sections/src/SectionCreateBatch.php @@ -27,7 +27,8 @@ public static function process(SectionManager $section_manager, array $bundle, $ // The basic query to retrieve base object ids. $query = \Drupal::entityQuery('base_object') - ->condition('type', $bundle, 'IN'); + ->condition('type', $bundle, 'IN') + ->accessCheck(FALSE); $result = $query->execute(); diff --git a/html/modules/custom/hpc_common/src/Plugin/HPCBlockBase.php b/html/modules/custom/hpc_common/src/Plugin/HPCBlockBase.php index 4334d0cfd..f06f8edf0 100644 --- a/html/modules/custom/hpc_common/src/Plugin/HPCBlockBase.php +++ b/html/modules/custom/hpc_common/src/Plugin/HPCBlockBase.php @@ -8,6 +8,7 @@ use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\hpc_common\Helpers\ContextHelper; use Drupal\hpc_common\Helpers\RequestHelper; +use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage; use Drupal\layout_builder\SectionStorageInterface; use Drupal\node\Entity\Node; use Drupal\node\NodeInterface; @@ -385,7 +386,7 @@ public function setPage($page_parameters = NULL) { $node = is_object($page_parameters['node']) ? $page_parameters['node'] : $entity_storage->load($page_parameters['node']); $this->page = $node->bundle() . '_node'; } - elseif (!empty($page_parameters['section_storage'])) { + elseif (!empty($page_parameters['section_storage']) && $page_parameters['section_storage'] instanceof OverridesSectionStorage) { // Layout builder editing context. $entity = $page_parameters['section_storage']->getContextValue('entity'); if ($entity->bundle() == 'page_variant') { @@ -398,6 +399,11 @@ public function setPage($page_parameters = NULL) { $this->page = $entity->bundle() . '_' . $entity->getEntityTypeId(); } } + elseif (!empty($page_parameters['entity'])) { + // Content entity, e.g. node. + $entity = $page_parameters['entity']; + $this->page = $entity->bundle() . '_' . $entity->getEntityTypeId(); + } else { // No page identified. $this->page = FALSE;