diff --git a/core/misc/cspell/dictionary.txt b/core/misc/cspell/dictionary.txt index ef568bce5d0..a8fa87d2c26 100644 --- a/core/misc/cspell/dictionary.txt +++ b/core/misc/cspell/dictionary.txt @@ -572,6 +572,7 @@ fieldblock fieldbody fieldgroups fielditem +fieldlayout fieldlinks fieldnames fieldsets diff --git a/core/modules/layout_builder/src/EventSubscriber/PrepareLayout.php b/core/modules/layout_builder/src/EventSubscriber/PrepareLayout.php index b68092ce83b..e335b87ab83 100644 --- a/core/modules/layout_builder/src/EventSubscriber/PrepareLayout.php +++ b/core/modules/layout_builder/src/EventSubscriber/PrepareLayout.php @@ -69,13 +69,16 @@ class PrepareLayout implements EventSubscriberInterface { if ($this->layoutTempstoreRepository->has($section_storage)) { $this->messenger->addWarning($this->t('You have unsaved changes.')); } - // If the layout is an override that has not yet been overridden, copy the - // sections from the corresponding default. - elseif ($section_storage instanceof OverridesSectionStorageInterface && !$section_storage->isOverridden()) { - $sections = $section_storage->getDefaultSectionStorage()->getSections(); - foreach ($sections as $section) { - $section_storage->appendSection($section); + else { + // If the layout is an override that has not yet been overridden, copy the + // sections from the corresponding default. + if ($section_storage instanceof OverridesSectionStorageInterface && !$section_storage->isOverridden()) { + $sections = $section_storage->getDefaultSectionStorage()->getSections(); + foreach ($sections as $section) { + $section_storage->appendSection($section); + } } + // Add storage to tempstore regardless of what the storage is. $this->layoutTempstoreRepository->set($section_storage); } } diff --git a/core/modules/layout_builder/tests/modules/layout_builder_extra_field_test/layout_builder_extra_field_test.info.yml b/core/modules/layout_builder/tests/modules/layout_builder_extra_field_test/layout_builder_extra_field_test.info.yml new file mode 100644 index 00000000000..7afc000a83a --- /dev/null +++ b/core/modules/layout_builder/tests/modules/layout_builder_extra_field_test/layout_builder_extra_field_test.info.yml @@ -0,0 +1,5 @@ +name: 'Layout Builder Extra Field test' +type: module +description: 'Support module for testing layout building.' +package: Testing +version: VERSION diff --git a/core/modules/layout_builder/tests/modules/layout_builder_extra_field_test/layout_builder_extra_field_test.module b/core/modules/layout_builder/tests/modules/layout_builder_extra_field_test/layout_builder_extra_field_test.module new file mode 100644 index 00000000000..11192281b05 --- /dev/null +++ b/core/modules/layout_builder/tests/modules/layout_builder_extra_field_test/layout_builder_extra_field_test.module @@ -0,0 +1,32 @@ + t('New Extra Field'), + 'description' => t('New Extra Field description'), + 'weight' => 0, + ]; + return $extra; +} + +/** + * Implements hook_entity_node_view(). + */ +function layout_builder_extra_field_test_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { + if ($display->getComponent('layout_builder_extra_field_test')) { + $build['layout_builder_extra_field_test'] = [ + '#markup' => 'A new extra field.', + ]; + } +} diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php index af3183e9e91..50fb0e071ed 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php @@ -240,6 +240,30 @@ class LayoutBuilderUiTest extends WebDriverTestBase { $this->assertHighlightNotExists(); } + /** + * Tests removing newly added extra field. + */ + public function testNewExtraField() { + $assert_session = $this->assertSession(); + $page = $this->getSession()->getPage(); + + // At this point layout builder has been enabled for the test content type. + // Install a test module that creates a new extra field then clear cache. + \Drupal::service('module_installer')->install(['layout_builder_extra_field_test']); + \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions(); + + // View the layout and try to remove the new extra field. + $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout'); + $assert_session->pageTextContains('New Extra Field'); + $this->clickContextualLink('.block-extra-field-blocknodebundle-with-section-fieldlayout-builder-extra-field-test', 'Remove block'); + $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas')); + $assert_session->assertWaitOnAjaxRequest(); + $assert_session->pageTextContains('Are you sure you want to remove'); + $page->pressButton('Remove'); + $assert_session->assertWaitOnAjaxRequest(); + $assert_session->pageTextNotContains('New Extra Field'); + } + /** * Confirms the presence of the 'is-layout-builder-highlighted' class. *