diff --git a/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php b/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php index 42f35b47bb..d755d092d0 100644 --- a/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php +++ b/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php @@ -117,7 +117,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta */ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { $this->plugin->validateConfigurationForm($form, $form_state); - if ($this->hasMenuOverrides()) { + if (!$this->hasMenuOverrides()) { $this->getEntityForm($this->menu)->validateForm($form, $form_state); } } @@ -127,7 +127,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { $this->plugin->submitConfigurationForm($form, $form_state); - if ($this->hasMenuOverrides()) { + if (!$this->hasMenuOverrides()) { $this->getEntityForm($this->menu)->submitForm($form, $form_state); $this->menu->save(); } diff --git a/core/modules/settings_tray/tests/modules/settings_tray_override_test/src/ConfigOverrider.php b/core/modules/settings_tray/tests/modules/settings_tray_override_test/src/ConfigOverrider.php index 0dcd9e608c..6921fa8e0d 100644 --- a/core/modules/settings_tray/tests/modules/settings_tray_override_test/src/ConfigOverrider.php +++ b/core/modules/settings_tray/tests/modules/settings_tray_override_test/src/ConfigOverrider.php @@ -19,7 +19,9 @@ class ConfigOverrider implements ConfigFactoryOverrideInterface { public function loadOverrides($names) { $overrides = []; if (in_array('block.block.overridden_block', $names)) { - $overrides = $overrides + ['block.block.overridden_block' => ['settings' => ['label' => 'Now this will be the label.']]]; + if (\Drupal::state()->get('settings_tray_override_test.block')) { + $overrides = $overrides + ['block.block.overridden_block' => ['settings' => ['label' => 'Now this will be the label.']]]; + } } if (in_array('system.site', $names)) { if (\Drupal::state()->get('settings_tray_override_test.site_name')) { diff --git a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php index 626fcad769..9cf66cc734 100644 --- a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php +++ b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php @@ -588,7 +588,7 @@ protected function getTestThemes() { /** * Tests that blocks with configuration overrides are disabled. */ - public function testOverriddenConfigRemoved() { + public function testOverriddenBlock() { $web_assert = $this->assertSession(); $page = $this->getSession()->getPage(); $overridden_block = $this->placeBlock('system_powered_by_block', [ @@ -596,6 +596,23 @@ public function testOverriddenConfigRemoved() { 'label_display' => 1, 'label' => 'This will be overridden.', ]); + $this->drupalGet('user'); + $block_selector = $this->getBlockSelector($overridden_block); + // Confirm the block is marked as Settings Tray editable. + $this->assertEquals('editable', $page->find('css', $block_selector)->getAttribute('data-drupal-settingstray')); + // Confirm the label is not overridden. + $web_assert->elementContains('css', $block_selector, 'This will be overridden.'); + $this->enableEditMode(); + $this->openBlockForm($block_selector); + + + // Confirm the block Settings Tray functionality is disabled when block is + // overridden. + $this->container->get('state')->set('settings_tray_override_test.block', TRUE); + $overridden_block->save(); + $block_config = \Drupal::configFactory()->getEditable('block.block.overridden_block'); + $block_config->set('settings', $block_config->get('settings'))->save(); + $this->drupalGet('user'); $this->assertOverriddenBlockDisabled($overridden_block, 'Now this will be the label.'); @@ -611,12 +628,23 @@ public function testOverriddenConfigRemoved() { // Confirm the label is not overridden. $web_assert->elementContains('css', $block_selector, 'Labely label'); $this->enableEditMode(); - $this->openBlockForm($this->getBlockSelector($block)); + $this->openBlockForm($block_selector); + + + } + + /** + * Test blocks with overridden related configuration removed when overridden. + */ + public function testOverriddenConfigurationRemoved() { + $web_assert = $this->assertSession(); + $page = $this->getSession()->getPage(); // Confirm the branding block does include 'site_information' section when // the site name is not overridden. $branding_block = $this->placeBlock('system_branding_block'); $this->drupalGet('user'); + $this->enableEditMode(); $this->openBlockForm($this->getBlockSelector($branding_block)); $web_assert->fieldExists('settings[site_information][site_name]'); // Confirm the branding block does not include 'site_information' section @@ -644,6 +672,7 @@ public function testOverriddenConfigRemoved() { $menu_block = $this->placeBlock('system_menu_block:main'); $web_assert->assertWaitOnAjaxRequest(); $this->drupalGet('user'); + $web_assert->pageTextContains('This is on the menu'); $this->openBlockForm($this->getBlockSelector($menu_block)); $web_assert->elementExists('css', '#menu-overview'); @@ -651,6 +680,9 @@ public function testOverriddenConfigRemoved() { // overridden. $this->container->get('state')->set('settings_tray_override_test.menu', TRUE); $this->drupalGet('user'); + $web_assert->pageTextContains('This is on the menu'); + $menu_with_overrides = \Drupal::configFactory()->get('system.menu.main')->get(); + $menu_without_overrides = \Drupal::configFactory()->getEditable('system.menu.main')->get(); $this->openBlockForm($this->getBlockSelector($menu_block)); $web_assert->elementNotExists('css', '#menu-overview'); $page->pressButton('Save Main navigation'); @@ -659,8 +691,10 @@ public function testOverriddenConfigRemoved() { // Confirm we did not save changes to the configuration. $this->assertEquals('Labely label', \Drupal::configFactory()->get('system.menu.main')->get('label')); $this->assertEquals('Main navigation', \Drupal::configFactory()->getEditable('system.menu.main')->get('label')); + $this->assertEquals($menu_with_overrides, \Drupal::configFactory()->get('system.menu.main')->get()); + $this->assertEquals($menu_without_overrides, \Drupal::configFactory()->getEditable('system.menu.main')->get()); + $web_assert->pageTextContains('This is on the menu'); } - /** * Asserts that an overridden block has Settings Tray disabled. *