diff --git a/core/config/schema/core.data_types.schema.yml b/core/config/schema/core.data_types.schema.yml index b3941643c5dac52ec22f7b9d17b394c5303e8980..be92cd96bb99f82bf8b7c2877199024568c8b87a 100644 --- a/core/config/schema/core.data_types.schema.yml +++ b/core/config/schema/core.data_types.schema.yml @@ -358,6 +358,10 @@ display_variant.plugin: layout_plugin.settings: type: mapping label: 'Layout settings' + mapping: + label: + type: label + label: 'Label' layout_plugin.settings.*: type: layout_plugin.settings diff --git a/core/lib/Drupal/Core/Layout/LayoutDefault.php b/core/lib/Drupal/Core/Layout/LayoutDefault.php index 6e53d00f444b50335211fcad7371c3baf213df93..175844fe1e33307d0b72e3813ae2bce0d2a3db51 100644 --- a/core/lib/Drupal/Core/Layout/LayoutDefault.php +++ b/core/lib/Drupal/Core/Layout/LayoutDefault.php @@ -3,12 +3,14 @@ namespace Drupal\Core\Layout; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginFormInterface; /** * Provides a default class for Layout plugins. */ -class LayoutDefault extends PluginBase implements LayoutInterface { +class LayoutDefault extends PluginBase implements LayoutInterface, PluginFormInterface { /** * The layout definition. @@ -63,7 +65,9 @@ public function setConfiguration(array $configuration) { * {@inheritdoc} */ public function defaultConfiguration() { - return []; + return [ + 'label' => '', + ]; } /** @@ -82,4 +86,29 @@ public function getPluginDefinition() { return parent::getPluginDefinition(); } + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + $form['label'] = [ + '#type' => 'textfield', + '#title' => $this->t('Administrative label'), + '#default_value' => $this->configuration['label'], + ]; + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + $this->configuration['label'] = $form_state->getValue('label'); + } + } diff --git a/core/modules/field_layout/tests/src/Kernel/FieldLayoutEntityDisplayTest.php b/core/modules/field_layout/tests/src/Kernel/FieldLayoutEntityDisplayTest.php index 3ca5e596ea83aa29f4f1181d85bde90360bb862f..e0d450eb4e5d19149f43898bc3abebd36c24ef88 100644 --- a/core/modules/field_layout/tests/src/Kernel/FieldLayoutEntityDisplayTest.php +++ b/core/modules/field_layout/tests/src/Kernel/FieldLayoutEntityDisplayTest.php @@ -41,7 +41,9 @@ public function testPreSave() { 'third_party_settings' => [ 'field_layout' => [ 'id' => 'layout_onecol', - 'settings' => [], + 'settings' => [ + 'label' => '', + ], ], ], 'id' => 'entity_test.entity_test.default', @@ -144,7 +146,9 @@ public function testPreSave() { // The layout has been updated. $expected['third_party_settings']['field_layout'] = [ 'id' => 'test_layout_content_and_footer', - 'settings' => [], + 'settings' => [ + 'label' => '', + ], ]; // The field remains in its current region instead of moving to the default. $this->assertEntityValues($expected, $entity_display->toArray()); diff --git a/core/modules/field_layout/tests/src/Unit/FieldLayoutBuilderTest.php b/core/modules/field_layout/tests/src/Unit/FieldLayoutBuilderTest.php index 44332987cdcc9c8f17ef448d59ff1ad3b705288e..b578694826ef3ed399feb681afe549356c2260e1 100644 --- a/core/modules/field_layout/tests/src/Unit/FieldLayoutBuilderTest.php +++ b/core/modules/field_layout/tests/src/Unit/FieldLayoutBuilderTest.php @@ -143,7 +143,9 @@ public function testBuildView() { '#markup' => 'Test1', ], ], - '#settings' => [], + '#settings' => [ + 'label' => '', + ], '#layout' => $this->pluginDefinition, '#theme' => 'layout__twocol', '#attached' => [ @@ -241,7 +243,9 @@ public function testBuildForm() { '#process' => ['\Drupal\Core\Render\Element\RenderElement::processGroup'], '#pre_render' => ['\Drupal\Core\Render\Element\RenderElement::preRenderGroup'], ], - '#settings' => [], + '#settings' => [ + 'label' => '', + ], '#layout' => $this->pluginDefinition, '#theme' => 'layout__twocol', '#attached' => [ diff --git a/core/modules/layout_builder/src/Element/LayoutBuilder.php b/core/modules/layout_builder/src/Element/LayoutBuilder.php index c2154f537bb4fa899b935aef7f6fb894c8ab09cb..80dcff90f7f3b4365b4ebe33dda84140afdadf56 100644 --- a/core/modules/layout_builder/src/Element/LayoutBuilder.php +++ b/core/modules/layout_builder/src/Element/LayoutBuilder.php @@ -244,6 +244,9 @@ protected function buildAdministrativeSection(SectionStorageInterface $section_s $section = $section_storage->getSection($delta); $layout = $section->getLayout(); + $layout_settings = $section->getLayoutSettings(); + $section_label = !empty($layout_settings['label']) ? $layout_settings['label'] : $this->t('Section @section', ['@section' => $delta + 1]); + $build = $section->toRenderArray($this->getAvailableContexts($section_storage), TRUE); $layout_definition = $layout->getPluginDefinition(); @@ -279,7 +282,7 @@ protected function buildAdministrativeSection(SectionStorageInterface $section_s $build[$region]['layout_builder_add_block']['link'] = [ '#type' => 'link', // Add one to the current delta since it is zero-indexed. - '#title' => $this->t('Add block <span class="visually-hidden">in section @section, @region region</span>', ['@section' => $delta + 1, '@region' => $region_labels[$region]]), + '#title' => $this->t('Add block <span class="visually-hidden">in @section, @region region</span>', ['@section' => $section_label, '@region' => $region_labels[$region]]), '#url' => Url::fromRoute('layout_builder.choose_block', [ 'section_storage_type' => $storage_type, @@ -310,9 +313,9 @@ protected function buildAdministrativeSection(SectionStorageInterface $section_s $build[$region]['#attributes']['class'][] = 'layout-builder__region'; $build[$region]['#attributes']['class'][] = 'js-layout-builder-region'; $build[$region]['#attributes']['role'] = 'group'; - $build[$region]['#attributes']['aria-label'] = $this->t('@region region in section @section', [ + $build[$region]['#attributes']['aria-label'] = $this->t('@region region in @section', [ '@region' => $info['label'], - '@section' => $delta + 1, + '@section' => $section_label, ]); // Get weights of all children for use by the region label. @@ -349,11 +352,11 @@ protected function buildAdministrativeSection(SectionStorageInterface $section_s '#attributes' => [ 'class' => ['layout-builder__section'], 'role' => 'group', - 'aria-label' => $this->t('Section @section', ['@section' => $delta + 1]), + 'aria-label' => $section_label, ], 'remove' => [ '#type' => 'link', - '#title' => $this->t('Remove section <span class="visually-hidden">@section</span>', ['@section' => $delta + 1]), + '#title' => $this->t('Remove @section', ['@section' => $section_label]), '#url' => Url::fromRoute('layout_builder.remove_section', [ 'section_storage_type' => $storage_type, 'section_storage' => $storage_id, @@ -372,16 +375,12 @@ protected function buildAdministrativeSection(SectionStorageInterface $section_s // The section label is added to sections without a "Configure section" // link, and is only visible when the move block dialog is open. 'section_label' => [ - '#markup' => $this->t('<span class="layout-builder__section-label" aria-hidden="true">Section @section</span>', ['@section' => $delta + 1]), + '#markup' => $this->t('<span class="layout-builder__section-label" aria-hidden="true">@section</span>', ['@section' => $section_label]), '#access' => !$layout instanceof PluginFormInterface, ], 'configure' => [ '#type' => 'link', - // There are two instances of @section, the one wrapped in - // .visually-hidden is for screen readers. The one wrapped in - // .layout-builder__section-label is only visible when the - // move block dialog is open and it is not seen by screen readers. - '#title' => $this->t('Configure section <span class="visually-hidden">@section</span><span aria-hidden="true" class="layout-builder__section-label">@section</span>', ['@section' => $delta + 1]), + '#title' => $this->t('Configure @section', ['@section' => $section_label]), '#access' => $layout instanceof PluginFormInterface, '#url' => Url::fromRoute('layout_builder.configure_section', [ 'section_storage_type' => $storage_type, diff --git a/core/modules/layout_builder/src/Field/LayoutSectionItemList.php b/core/modules/layout_builder/src/Field/LayoutSectionItemList.php index 58e78f2562631839c57a352edf149e7d3a3ed173..3243be97a6b654c3e9801d0d72b15dc292ef210f 100644 --- a/core/modules/layout_builder/src/Field/LayoutSectionItemList.php +++ b/core/modules/layout_builder/src/Field/LayoutSectionItemList.php @@ -22,12 +22,18 @@ class LayoutSectionItemList extends FieldItemList implements SectionListInterfac use SectionStorageTrait; + /** + * Numerically indexed array of field items. + * + * @var \Drupal\layout_builder\Plugin\Field\FieldType\LayoutSectionItem[] + */ + protected $list = []; + /** * {@inheritdoc} */ public function getSections() { $sections = []; - /** @var \Drupal\layout_builder\Plugin\Field\FieldType\LayoutSectionItem $item */ foreach ($this->list as $delta => $item) { $sections[$delta] = $item->section; } @@ -60,6 +66,18 @@ public function getEntity() { return $entity; } + /** + * {@inheritdoc} + */ + public function preSave() { + parent::preSave(); + // Loop through each section and reconstruct it to ensure that all default + // values are present. + foreach ($this->list as $delta => $item) { + $item->section = Section::fromArray($item->section->toArray()); + } + } + /** * {@inheritdoc} */ diff --git a/core/modules/layout_builder/src/Form/ConfigureSectionForm.php b/core/modules/layout_builder/src/Form/ConfigureSectionForm.php index 3e58c668a0ed05ded144e548398b80f01ef5861d..074901c8a3146badf7aaec327d1492a2b541125a 100644 --- a/core/modules/layout_builder/src/Form/ConfigureSectionForm.php +++ b/core/modules/layout_builder/src/Form/ConfigureSectionForm.php @@ -111,6 +111,9 @@ public function buildForm(array $form, FormStateInterface $form_state, SectionSt if ($this->isUpdate) { $section = $this->sectionStorage->getSection($this->delta); + if ($label = $section->getLayoutSettings()['label']) { + $form['#title'] = $this->t('Configure @section', ['@section' => $label]); + } } else { $section = new Section($plugin_id); diff --git a/core/modules/layout_builder/src/Form/MoveBlockForm.php b/core/modules/layout_builder/src/Form/MoveBlockForm.php index 8bc7938963344c644b29322dc82384df8d67e1e1..b3fd9dcbf80c78115d06d5efe66a80fd75990714 100644 --- a/core/modules/layout_builder/src/Form/MoveBlockForm.php +++ b/core/modules/layout_builder/src/Form/MoveBlockForm.php @@ -123,12 +123,14 @@ public function buildForm(array $form, FormStateInterface $form_state, SectionSt foreach ($sections as $section_delta => $section) { $layout = $section->getLayout(); $layout_definition = $layout->getPluginDefinition(); - $section_label = $this->t('Section: @delta', ['@delta' => $section_delta + 1])->render(); + if (!($section_label = $section->getLayoutSettings()['label'])) { + $section_label = $this->t('Section: @delta', ['@delta' => $section_delta + 1])->render(); + } foreach ($layout_definition->getRegions() as $region_name => $region_info) { // Group regions by section. $region_options[$section_label]["$section_delta:$region_name"] = $this->t( - 'Section: @delta, Region: @region', - ['@delta' => $section_delta + 1, '@region' => $region_info['label']] + '@section, Region: @region', + ['@section' => $section_label, '@region' => $region_info['label']] ); } } diff --git a/core/modules/layout_builder/src/Form/RemoveSectionForm.php b/core/modules/layout_builder/src/Form/RemoveSectionForm.php index 7a0cb0fd4a1ed31d2fe8e3a0584f9af56169e099..a788698764f4122edf0e28c4a8f70ed832fdf45c 100644 --- a/core/modules/layout_builder/src/Form/RemoveSectionForm.php +++ b/core/modules/layout_builder/src/Form/RemoveSectionForm.php @@ -24,6 +24,10 @@ public function getFormId() { * {@inheritdoc} */ public function getQuestion() { + $configuration = $this->sectionStorage->getSection($this->delta)->getLayoutSettings(); + if ($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/src/Plugin/Layout/MultiWidthLayoutBase.php b/core/modules/layout_builder/src/Plugin/Layout/MultiWidthLayoutBase.php index 71ab112dfc7760b18f40faea6daaba21bc738067..9ad23e0a227b682dd2a569ca340d304c5587ee51 100644 --- a/core/modules/layout_builder/src/Plugin/Layout/MultiWidthLayoutBase.php +++ b/core/modules/layout_builder/src/Plugin/Layout/MultiWidthLayoutBase.php @@ -18,8 +18,9 @@ abstract class MultiWidthLayoutBase extends LayoutDefault implements PluginFormI * {@inheritdoc} */ public function defaultConfiguration() { + $configuration = parent::defaultConfiguration(); $width_classes = array_keys($this->getWidthOptions()); - return [ + return $configuration + [ 'column_widths' => array_shift($width_classes), ]; } @@ -35,19 +36,14 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#options' => $this->getWidthOptions(), '#description' => $this->t('Choose the column widths for this layout.'), ]; - return $form; - } - - /** - * {@inheritdoc} - */ - public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { + return parent::buildConfigurationForm($form, $form_state); } /** * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + parent::submitConfigurationForm($form, $form_state); $this->configuration['column_widths'] = $form_state->getValue('column_widths'); } diff --git a/core/modules/layout_builder/src/Section.php b/core/modules/layout_builder/src/Section.php index 73225d8fb55e3b8d379089c4d090fbac62870c5a..41fe13c57e676d8fd9d23330005618cfb6d57766 100644 --- a/core/modules/layout_builder/src/Section.php +++ b/core/modules/layout_builder/src/Section.php @@ -98,7 +98,7 @@ public function toRenderArray(array $contexts = [], $in_preview = FALSE) { * The layout plugin. */ public function getLayout() { - return $this->layoutPluginManager()->createInstance($this->getLayoutId(), $this->getLayoutSettings()); + return $this->layoutPluginManager()->createInstance($this->getLayoutId(), $this->layoutSettings); } /** @@ -124,7 +124,7 @@ public function getLayoutId() { * This method should only be used by code responsible for storing the data. */ public function getLayoutSettings() { - return $this->layoutSettings; + return $this->getLayout()->getConfiguration(); } /** diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php index 00f265559f4dcb2557aae275f56949c22d18bffa..c5efc3110df3c0c9c10c73046ecd3340334fcc0a 100644 --- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php @@ -296,8 +296,8 @@ public function testLayoutBuilderUi() { $assert_session->linkExists('Layout'); $this->clickLink('Layout'); $assert_session->pageTextContains('Placeholder for the "Extra label" field'); - $assert_session->linkExists('Remove section'); - $this->clickLink('Remove section'); + $assert_session->linkExists('Remove Section 1'); + $this->clickLink('Remove Section 1'); $page->pressButton('Remove'); // Add a new section. @@ -391,9 +391,16 @@ public function testLayoutBuilderUi() { $assert_session->pageTextNotContains('My text field'); $assert_session->elementNotExists('css', '.field--name-field-my-text'); + $this->clickLink('Add section'); + $this->clickLink('One column'); + $page->fillField('layout_settings[label]', 'My Cool Section'); + $page->pressButton('Add section'); + $expected_labels = [ - 'Section 1', - 'Content region in section 1', + 'My Cool Section', + 'Content region in My Cool Section', + 'Section 2', + 'Content region in Section 2', ]; $labels = []; foreach ($page->findAll('css', '[role="group"]') as $element) { @@ -529,6 +536,7 @@ public function testPluginDependencies() { $this->clickLink('Add section'); $assert_session->linkExists('Layout plugin (with dependencies)'); $this->clickLink('Layout plugin (with dependencies)'); + $page->pressButton('Add section'); $assert_session->elementExists('css', '.layout--layout-test-dependencies-plugin'); $assert_session->elementExists('css', '.field--name-body'); $page->pressButton('Save layout'); @@ -939,6 +947,34 @@ public function testFormAlter() { $assert_session->pageTextContains('Layout Builder Component: system_powered_by_block'); } + /** + * Tests the functionality of custom section labels. + */ + public function testSectionLabels() { + $assert_session = $this->assertSession(); + $page = $this->getSession()->getPage(); + + $this->drupalLogin($this->drupalCreateUser([ + 'configure any layout', + 'administer node display', + ])); + + $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default'); + $page->checkField('layout[enabled]'); + $page->pressButton('Save'); + $page->checkField('layout[allow_custom]'); + $page->pressButton('Save'); + + $this->drupalGet('node/1/layout'); + $page->clickLink('Add section'); + $page->clickLink('One column'); + $page->fillField('layout_settings[label]', 'My Cool Section'); + $page->pressButton('Add section'); + $assert_session->pageTextContains('My Cool Section'); + $page->pressButton('Save layout'); + $assert_session->pageTextNotContains('My Cool Section'); + } + /** * Tests that sections can provide custom attributes. */ @@ -955,6 +991,7 @@ public function testCustomSectionAttributes() { $page->clickLink('Manage layout'); $page->clickLink('Add section'); $page->clickLink('Layout Builder Test Plugin'); + $page->pressButton('Add section'); // See \Drupal\layout_builder_test\Plugin\Layout\LayoutBuilderTestPlugin::build(). $assert_session->elementExists('css', '.go-birds'); } @@ -1150,7 +1187,7 @@ public function testRemovingAllSections() { $assert_session->elementsCount('css', '.layout-builder__add-section', 2); // Remove the only section from the override. - $page->clickLink('Remove section'); + $page->clickLink('Remove Section 1'); $page->pressButton('Remove'); $assert_session->elementsCount('css', '.layout', 0); $assert_session->elementsCount('css', '.layout-builder__add-block', 0); @@ -1169,6 +1206,7 @@ public function testRemovingAllSections() { // Add one section to the override. $page->clickLink('Add section'); $page->clickLink('One column'); + $page->pressButton('Add section'); $assert_session->elementsCount('css', '.layout', 1); $assert_session->elementsCount('css', '.layout-builder__add-block', 1); $assert_session->elementsCount('css', '.layout-builder__add-section', 2); @@ -1184,7 +1222,7 @@ public function testRemovingAllSections() { $assert_session->elementsCount('css', '.layout-builder__add-section', 2); // Remove the only section from the default. - $page->clickLink('Remove section'); + $page->clickLink('Remove Section 1'); $page->pressButton('Remove'); $assert_session->elementsCount('css', '.layout', 0); $assert_session->elementsCount('css', '.layout-builder__add-block', 0); @@ -1219,10 +1257,10 @@ protected function assertCorrectLayouts() { $assert_session = $this->assertSession(); // Ensure the layouts provided by layout_builder are available. $expected_layouts_hrefs = [ - 'layout_builder/add/section/overrides/node.1/0/layout_onecol', + 'layout_builder/configure/section/overrides/node.1/0/layout_onecol', 'layout_builder/configure/section/overrides/node.1/0/layout_twocol_section', 'layout_builder/configure/section/overrides/node.1/0/layout_threecol_section', - 'layout_builder/add/section/overrides/node.1/0/layout_fourcol_section', + 'layout_builder/configure/section/overrides/node.1/0/layout_fourcol_section', ]; foreach ($expected_layouts_hrefs as $expected_layouts_href) { $assert_session->linkByHrefExists($expected_layouts_href); @@ -1236,6 +1274,7 @@ protected function assertCorrectLayouts() { ]; foreach ($unexpected_layouts as $unexpected_layout) { $assert_session->linkByHrefNotExists("layout_builder/add/section/overrides/node.1/0/$unexpected_layout"); + $assert_session->linkByHrefNotExists("layout_builder/configure/section/overrides/node.1/0/$unexpected_layout"); } } diff --git a/core/modules/layout_builder/tests/src/Functional/Update/LayoutBuilderEnableUpdatePathTest.php b/core/modules/layout_builder/tests/src/Functional/Update/LayoutBuilderEnableUpdatePathTest.php index 413d0eae0ab35a149af66ad6d7d803605821b8ca..3531160ced4b87c0a7e7212555d9d0b7f915dc99 100644 --- a/core/modules/layout_builder/tests/src/Functional/Update/LayoutBuilderEnableUpdatePathTest.php +++ b/core/modules/layout_builder/tests/src/Functional/Update/LayoutBuilderEnableUpdatePathTest.php @@ -58,6 +58,7 @@ public function testRunUpdates() { // The display with existing sections is enabled while the other is not. $expected['enabled'] = TRUE; + $expected['sections'][0]['layout_settings']['label'] = ''; $this->assertLayoutBuilderSettings($expected, 'block_content', 'basic', 'default'); $this->assertLayoutBuilderSettings(NULL, 'node', 'page', 'default'); diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php index 7c0830a79ddb539b63fc5488fa76c7ff0b25aa7a..4f70581eed4122d6e5e935ca4f024ad156ee54c2 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php @@ -224,16 +224,16 @@ public function testLayoutBuilderUi() { $assert_session->pageTextContains('This is the block content'); // Remove both sections. - $assert_session->linkExists('Remove section'); - $this->clickLink('Remove section'); + $assert_session->linkExists('Remove Section 1'); + $this->clickLink('Remove Section 1'); $this->assertOffCanvasFormAfterWait('layout_builder_remove_section'); $assert_session->pageTextContains('Are you sure you want to remove section 1?'); $assert_session->pageTextContains('This action cannot be undone.'); $page->pressButton('Remove'); $assert_session->assertWaitOnAjaxRequest(); - $assert_session->linkExists('Remove section'); - $this->clickLink('Remove section'); + $assert_session->linkExists('Remove Section 1'); + $this->clickLink('Remove Section 1'); $this->assertOffCanvasFormAfterWait('layout_builder_remove_section'); $page->pressButton('Remove'); $assert_session->assertWaitOnAjaxRequest(); @@ -301,8 +301,8 @@ public function testConfigurableLayoutSections() { $assert_session->linkExists('Add block'); // Configure the existing section. - $assert_session->linkExists('Configure section 1'); - $this->clickLink('Configure section 1'); + $assert_session->linkExists('Configure Section 1'); + $this->clickLink('Configure Section 1'); $this->assertOffCanvasFormAfterWait('layout_builder_configure_section'); $page->fillField('layout_settings[setting_1]', 'Test setting value'); $page->pressButton('Update'); @@ -341,6 +341,7 @@ public function testLayoutNoDialog() { ])); $assert_session->linkExists('One column'); $this->clickLink('One column'); + $page->pressButton('Add section'); // Add a block. $this->drupalGet(Url::fromRoute('layout_builder.add_block', [ diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php index 1f39a538a4de0c79a878741ff42ef7c4aad05ead..5ec449b28a9a80e9a85b562f5f5bcaa9ab6db5b2 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php @@ -64,18 +64,18 @@ public function testReloadWithNoSections() { // Remove all of the sections from the page. $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout'); - $page->clickLink('Remove section'); + $page->clickLink('Remove Section 1'); $assert_session->assertWaitOnAjaxRequest(); $page->pressButton('Remove'); $assert_session->assertWaitOnAjaxRequest(); // Assert that there are no sections on the page. - $assert_session->pageTextNotContains('Remove section'); + $assert_session->pageTextNotContains('Remove Section 1'); $assert_session->pageTextNotContains('Add block'); // Reload the page. $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout'); // Assert that there are no sections on the page. - $assert_session->pageTextNotContains('Remove section'); + $assert_session->pageTextNotContains('Remove Section 1'); $assert_session->pageTextNotContains('Add block'); } @@ -114,6 +114,8 @@ protected function assertModifiedLayout($path) { $assert_session->pageTextNotContains('You have unsaved changes.'); $page->clickLink('One column'); $assert_session->assertWaitOnAjaxRequest(); + $page->pressButton('Add section'); + $assert_session->assertWaitOnAjaxRequest(); $assert_session->pageTextContainsOnce('You have unsaved changes.'); // Reload the page. @@ -190,14 +192,14 @@ public function testAddHighlights() { $this->assertHighlightNotExists(); // The highlight is present when the "Configure section" dialog is open. - $page->clickLink('Configure section'); + $page->clickLink('Configure Section 1'); $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas')); $this->assertHighlightedElement('[data-layout-builder-highlight-id="section-update-0"]'); $page->pressButton('Close'); $this->assertHighlightNotExists(); - // The highlight is present when the "Remove section" dialog is open. - $page->clickLink('Remove section'); + // The highlight is present when the "Remove Section" dialog is open. + $page->clickLink('Remove Section 1'); $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas')); $assert_session->assertWaitOnAjaxRequest(); $this->assertHighlightedElement('[data-layout-builder-highlight-id="section-update-0"]'); diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/TestMultiWidthLayoutsTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/TestMultiWidthLayoutsTest.php index ecfcf27a0501f30c909d839f47568fe30b6b2649..86edc44efdfb8d3e93b6b8e4f3edf5587a0d1a94 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/TestMultiWidthLayoutsTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/TestMultiWidthLayoutsTest.php @@ -90,15 +90,15 @@ public function testWidthChange() { $this->assertWidthClassApplied($width_option['class'] . $width); foreach ($width_option['widths'] as $width) { $width_class = $width_option['class'] . $width; - $assert_session->linkExists('Configure section 1'); - $page->clickLink('Configure section 1'); + $assert_session->linkExists('Configure Section 1'); + $page->clickLink('Configure Section 1'); $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas input[type="submit"][value="Update"]')); $page->findField('layout_settings[column_widths]')->setValue($width); $page->pressButton("Update"); $this->assertWidthClassApplied($width_class); } - $assert_session->linkExists('Remove section'); - $this->clickLink('Remove section'); + $assert_session->linkExists('Remove Section 1'); + $this->clickLink('Remove Section 1'); $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas input[type="submit"][value="Remove"]')); $page->pressButton('Remove'); $assert_session->assertNoElementAfterWait('css', ".$width_class"); diff --git a/core/modules/layout_builder/tests/src/Kernel/DefaultsSectionStorageTest.php b/core/modules/layout_builder/tests/src/Kernel/DefaultsSectionStorageTest.php index 30eb346e41e5cfc4633ad9279322836bd2b79442..1a3eeeb7e8f05be37a6d287ef63271ad292ee494 100644 --- a/core/modules/layout_builder/tests/src/Kernel/DefaultsSectionStorageTest.php +++ b/core/modules/layout_builder/tests/src/Kernel/DefaultsSectionStorageTest.php @@ -69,7 +69,10 @@ public function testConfigInstall() { $section = $display->getSection(0); $this->assertInstanceOf(Section::class, $section); $this->assertEquals('layout_twocol_section', $section->getLayoutId()); - $this->assertEquals(['column_widths' => '50-50'], $section->getLayoutSettings()); + $this->assertEquals([ + 'column_widths' => '50-50', + 'label' => '', + ], $section->getLayoutSettings()); } /** diff --git a/core/modules/layout_builder/tests/src/Kernel/OverridesSectionStorageTest.php b/core/modules/layout_builder/tests/src/Kernel/OverridesSectionStorageTest.php index aa2532e1bbdff4dfa38391b87b17156cb0820637..532a406adb6b657d8cae22f96d61fc2bd61cdcf3 100644 --- a/core/modules/layout_builder/tests/src/Kernel/OverridesSectionStorageTest.php +++ b/core/modules/layout_builder/tests/src/Kernel/OverridesSectionStorageTest.php @@ -120,7 +120,7 @@ public function testAccess($expected, $is_enabled, array $section_data, array $p */ public function providerTestAccess() { $section_data = [ - new Section('layout_default', [], [ + new Section('layout_onecol', [], [ 'first-uuid' => new SectionComponent('first-uuid', 'content', ['id' => 'foo']), ]), ]; @@ -286,7 +286,7 @@ public function testIsOverridden() { ->save(); $entity = EntityTest::create(); - $entity->set(OverridesSectionStorage::FIELD_NAME, [new Section('layout_default')]); + $entity->set(OverridesSectionStorage::FIELD_NAME, [new Section('layout_onecol')]); $entity->save(); $entity = EntityTest::load($entity->id()); diff --git a/core/modules/layout_builder/tests/src/Kernel/SectionListTraitTest.php b/core/modules/layout_builder/tests/src/Kernel/SectionListTraitTest.php index 023200e2c090af591ac27e7ebef6b2d061babec6..02be9fefcf152d7d6c92cb4803800c121afff231 100644 --- a/core/modules/layout_builder/tests/src/Kernel/SectionListTraitTest.php +++ b/core/modules/layout_builder/tests/src/Kernel/SectionListTraitTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\layout_builder\Kernel; +use Drupal\layout_builder\Section; use Drupal\layout_builder\SectionListInterface; use Drupal\layout_builder\SectionStorage\SectionStorageTrait; @@ -47,7 +48,11 @@ class TestSectionList implements SectionListInterface { * TestSectionList constructor. */ public function __construct(array $sections) { - $this->setSections($sections); + // Loop through each section and reconstruct it to ensure that all default + // values are present. + foreach ($sections as $section) { + $this->sections[] = Section::fromArray($section->toArray()); + } } /** diff --git a/core/modules/layout_builder/tests/src/Kernel/SectionStorageTestBase.php b/core/modules/layout_builder/tests/src/Kernel/SectionStorageTestBase.php index 5ec39f25d59b11ff00d8b2cb593f9b36c39db669..65a06183cdc9153966b2d50d4c0690bd9730722f 100644 --- a/core/modules/layout_builder/tests/src/Kernel/SectionStorageTestBase.php +++ b/core/modules/layout_builder/tests/src/Kernel/SectionStorageTestBase.php @@ -62,7 +62,7 @@ abstract protected function getSectionStorage(array $section_data); */ public function testGetSections() { $expected = [ - new Section('layout_test_plugin', [], [ + new Section('layout_test_plugin', ['setting_1' => 'Default'], [ 'first-uuid' => new SectionComponent('first-uuid', 'content', ['id' => 'foo']), ]), new Section('layout_test_plugin', ['setting_1' => 'bar'], [ @@ -93,16 +93,16 @@ public function testGetSectionInvalidDelta() { */ public function testInsertSection() { $expected = [ - new Section('layout_test_plugin', [], [ + new Section('layout_test_plugin', ['setting_1' => 'Default'], [ 'first-uuid' => new SectionComponent('first-uuid', 'content', ['id' => 'foo']), ]), - new Section('setting_1'), + new Section('layout_onecol'), new Section('layout_test_plugin', ['setting_1' => 'bar'], [ 'second-uuid' => new SectionComponent('second-uuid', 'content', ['id' => 'foo']), ]), ]; - $this->sectionStorage->insertSection(1, new Section('setting_1')); + $this->sectionStorage->insertSection(1, new Section('layout_onecol')); $this->assertSections($expected); } @@ -111,16 +111,16 @@ public function testInsertSection() { */ public function testAppendSection() { $expected = [ - new Section('layout_test_plugin', [], [ + new Section('layout_test_plugin', ['setting_1' => 'Default'], [ 'first-uuid' => new SectionComponent('first-uuid', 'content', ['id' => 'foo']), ]), new Section('layout_test_plugin', ['setting_1' => 'bar'], [ 'second-uuid' => new SectionComponent('second-uuid', 'content', ['id' => 'foo']), ]), - new Section('foo'), + new Section('layout_onecol'), ]; - $this->sectionStorage->appendSection(new Section('foo')); + $this->sectionStorage->appendSection(new Section('layout_onecol')); $this->assertSections($expected); } @@ -181,11 +181,11 @@ public function testRemoveMultipleSections() { * Tests __clone(). */ public function testClone() { - $this->assertSame([], $this->sectionStorage->getSection(0)->getLayoutSettings()); + $this->assertSame(['setting_1' => 'Default'], $this->sectionStorage->getSection(0)->getLayoutSettings()); $new_section_storage = clone $this->sectionStorage; $new_section_storage->getSection(0)->setLayoutSettings(['asdf' => 'qwer']); - $this->assertSame([], $this->sectionStorage->getSection(0)->getLayoutSettings()); + $this->assertSame(['setting_1' => 'Default'], $this->sectionStorage->getSection(0)->getLayoutSettings()); } /** diff --git a/core/modules/layout_builder/tests/src/Kernel/TranslatableFieldTest.php b/core/modules/layout_builder/tests/src/Kernel/TranslatableFieldTest.php index d22d7ea287774c4023d4450fe1149233f7b1c316..23d1dd1034a160fd2c945179b69bef83a5f37c42 100644 --- a/core/modules/layout_builder/tests/src/Kernel/TranslatableFieldTest.php +++ b/core/modules/layout_builder/tests/src/Kernel/TranslatableFieldTest.php @@ -67,7 +67,7 @@ protected function setUp() { */ public function testSectionsClearedOnCreateTranslation() { $section_data = [ - new Section('layout_default', [], [ + new Section('layout_onecol', [], [ 'first-uuid' => new SectionComponent('first-uuid', 'content', ['id' => 'foo']), ]), ]; diff --git a/core/modules/system/system.post_update.php b/core/modules/system/system.post_update.php index 11f72ecfebb43fa3384b6bc7026f0c28ca8b9b08..5f6c9f766348690c86070205fa3a7bd620d8a5f9 100644 --- a/core/modules/system/system.post_update.php +++ b/core/modules/system/system.post_update.php @@ -206,3 +206,10 @@ function system_post_update_add_expand_all_items_key_in_system_menu_block(&$sand function system_post_update_clear_menu_cache() { // Empty post-update hook. } + +/** + * Clear the schema cache. + */ +function system_post_update_layout_plugin_schema_change() { + // Empty post-update hook. +} diff --git a/core/profiles/demo_umami/config/install/core.entity_view_display.node.recipe.full.yml b/core/profiles/demo_umami/config/install/core.entity_view_display.node.recipe.full.yml index 4eeb7d2dc75fd01711cbf76829729c2b831c9e4d..f0a384a215a28ce5e7ee0c65f91e363710141c79 100644 --- a/core/profiles/demo_umami/config/install/core.entity_view_display.node.recipe.full.yml +++ b/core/profiles/demo_umami/config/install/core.entity_view_display.node.recipe.full.yml @@ -28,7 +28,8 @@ third_party_settings: sections: - layout_id: layout_onecol - layout_settings: { } + layout_settings: + label: '' components: 44801518-fe93-421a-bdcb-550493c7925d: uuid: 44801518-fe93-421a-bdcb-550493c7925d diff --git a/core/tests/Drupal/Tests/Core/Layout/LayoutDefaultTest.php b/core/tests/Drupal/Tests/Core/Layout/LayoutDefaultTest.php index 91aadb7d9b2cff857abfad20c9c6d19bd4bbf4b5..af9cc38759bbc2277cdb5305d28f51a4426bf507 100644 --- a/core/tests/Drupal/Tests/Core/Layout/LayoutDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Layout/LayoutDefaultTest.php @@ -30,7 +30,9 @@ public function testBuild($regions, $expected) { ], ]); $expected += [ - '#settings' => [], + '#settings' => [ + 'label' => '', + ], '#layout' => $definition, '#theme' => 'layout', '#attached' => [