diff --git a/core/modules/layout_builder/src/Form/RemoveSectionForm.php b/core/modules/layout_builder/src/Form/RemoveSectionForm.php index a788698764f4122edf0e28c4a8f70ed832fdf45c..8fd4aec7c51fd0e783416fab1e43c1262815f15d 100644 --- a/core/modules/layout_builder/src/Form/RemoveSectionForm.php +++ b/core/modules/layout_builder/src/Form/RemoveSectionForm.php @@ -25,7 +25,9 @@ public function getFormId() { */ public function getQuestion() { $configuration = $this->sectionStorage->getSection($this->delta)->getLayoutSettings(); - if ($configuration['label']) { + // Layouts may choose to use a class that might not have a label + // configuration. + if (!empty($configuration['label'])) { return $this->t('Are you sure you want to remove @section?', ['@section' => $configuration['label']]); } return $this->t('Are you sure you want to remove section @section?', ['@section' => $this->delta + 1]); diff --git a/core/modules/layout_builder/tests/modules/layout_builder_test/src/Plugin/Layout/LayoutWithoutLabel.php b/core/modules/layout_builder/tests/modules/layout_builder_test/src/Plugin/Layout/LayoutWithoutLabel.php new file mode 100644 index 0000000000000000000000000000000000000000..9b32bbb1b90e29e0499b8455597ed68573e31ab6 --- /dev/null +++ b/core/modules/layout_builder/tests/modules/layout_builder_test/src/Plugin/Layout/LayoutWithoutLabel.php @@ -0,0 +1,42 @@ +pageTextNotContains('The first node body'); } + /** + * Tests removing section without layout label configuration. + */ + public function testRemovingSectionWithoutLayoutLabel() { + $assert_session = $this->assertSession(); + $page = $this->getSession()->getPage(); + + $this->drupalLogin($this->drupalCreateUser([ + 'configure any layout', + 'administer node display', + ])); + + // Enable overrides. + $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field'; + $this->drupalGet("$field_ui_prefix/display/default"); + $this->submitForm(['layout[enabled]' => TRUE], 'Save'); + $this->submitForm(['layout[allow_custom]' => TRUE], 'Save'); + + $this->drupalGet("$field_ui_prefix/display/default/layout"); + $page->clickLink('Add section'); + + $assert_session->linkExists('Layout Without Label'); + $page->clickLink('Layout Without Label'); + $page->pressButton('Add section'); + $assert_session->elementsCount('css', '.layout', 2); + + $assert_session->linkExists('Remove Section 1'); + $this->clickLink('Remove Section 1'); + $page->pressButton('Remove'); + + $assert_session->statusCodeEquals(200); + $assert_session->elementsCount('css', '.layout', 1); + } + /** * Asserts that the correct layouts are available. */