diff --git a/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php index 1bb24e07cb..14fa80ed50 100644 --- a/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php +++ b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php @@ -205,7 +205,11 @@ protected function addSectionField($entity_type_id, $bundle, $field_name) { * {@inheritdoc} */ protected function getDefaultRegion() { - return $this->getDefaultSection()->getDefaultRegion(); + if ($this->hasSection(0)) { + return $this->getSection(0)->getDefaultRegion(); + } + + return parent::getDefaultRegion(); } /** @@ -412,9 +416,10 @@ public function setComponent($name, array $options = []) { $configuration['formatter'] = array_intersect_key($options, $keys); $configuration['context_mapping']['entity'] = 'layout_builder.entity'; - $region = isset($options['region']) ? $options['region'] : $this->getDefaultRegion(); + $section = $this->getDefaultSection(); + $region = isset($options['region']) ? $options['region'] : $section->getDefaultRegion(); $new_component = (new SectionComponent(\Drupal::service('uuid')->generate(), $region, $configuration)); - $this->getDefaultSection()->appendComponent($new_component); + $section->appendComponent($new_component); } return $this; }