diff --git a/core/modules/settings_tray/settings_tray.module b/core/modules/settings_tray/settings_tray.module index 19f5d4b7c1..3d525ab310 100644 --- a/core/modules/settings_tray/settings_tray.module +++ b/core/modules/settings_tray/settings_tray.module @@ -68,6 +68,8 @@ function settings_tray_contextual_links_view_alter(&$element, $items) { * @internal */ function _settings_tray_has_block_overrides(BlockInterface $block) { + // @todo Replace the following with $block->hasOverrides() in https://www.drupal.org/project/drupal/issues/2910353 + // and remove the need for this function. return \Drupal::config($block->getEntityType()->getConfigPrefix() . '.' . $block->id())->hasOverrides(); } diff --git a/core/modules/settings_tray/src/Form/SystemBrandingOffCanvasForm.php b/core/modules/settings_tray/src/Form/SystemBrandingOffCanvasForm.php index 9a5547637e..94c8052648 100644 --- a/core/modules/settings_tray/src/Form/SystemBrandingOffCanvasForm.php +++ b/core/modules/settings_tray/src/Form/SystemBrandingOffCanvasForm.php @@ -99,7 +99,9 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - if ($site_info = $form_state->getValue('site_information')) { + $site_config = $this->configFactory->get('system.site'); + if (AccessResult::allowedIf(!$site_config->hasOverrides('name') && !$site_config->hasOverrides('slogan'))->isAllowed()) { + $site_info = $form_state->getValue('site_information'); $this->configFactory->getEditable('system.site') ->set('name', $site_info['site_name']) ->set('slogan', $site_info['site_slogan']) diff --git a/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php b/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php index 2c93cf343b..42f35b47bb 100644 --- a/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php +++ b/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php @@ -88,7 +88,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#type' => 'details', '#title' => $this->t('Edit menu %label', ['%label' => $this->menu->label()]), '#open' => TRUE, - '#access' => AccessResult::allowedIf(!\Drupal::config($this->menu->getEntityType()->getConfigPrefix() . '.' . $this->menu->id())->hasOverrides()), + '#access' => AccessResult::allowedIf(!$this->hasMenuOverrides()), ]; $form['entity_form'] += $this->getEntityForm($this->menu)->buildForm([], $form_state); @@ -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 ($form_state->hasValue('entity_form')) { + 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 ($form_state->hasValue('entity_form')) { + if ($this->hasMenuOverrides()) { $this->getEntityForm($this->menu)->submitForm($form, $form_state); $this->menu->save(); } @@ -153,7 +153,15 @@ protected function getEntityForm(MenuInterface $menu) { */ public function setPlugin(PluginInspectionInterface $plugin) { $this->plugin = $plugin; - $this->menu = $this->menuStorage->load($this->plugin->getDerivativeId()); + $this->menu = $this->menuStorage->loadOverrideFree($this->plugin->getDerivativeId()); + } + + /** + * @return bool + */ + protected function hasMenuOverrides() { + return \Drupal::config($this->menu->getEntityType() + ->getConfigPrefix() . '.' . $this->menu->id())->hasOverrides(); } } diff --git a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php index 5a6adb93df..626fcad769 100644 --- a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php +++ b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php @@ -625,18 +625,24 @@ public function testOverriddenConfigRemoved() { $this->drupalGet('user'); $this->openBlockForm($this->getBlockSelector($branding_block)); $web_assert->fieldNotExists('settings[site_information][site_name]'); + $page->pressButton('Save Site branding'); + $this->assertElementVisibleAfterWait('css', 'div:contains(The block configuration has been saved)'); + $web_assert->assertWaitOnAjaxRequest(); + // Confirm we did not save changes to the configuration. + $this->assertEquals('Llama Fan Club', \Drupal::configFactory()->get('system.site')->get('name')); + $this->assertEquals('Drupal', \Drupal::configFactory()->getEditable('system.site')->get('name')); // Add a link or the menu will not render. $menu_link_content = MenuLinkContent::create([ - 'title' => 'This is on the menu', - 'menu_name' => 'main', - 'link' => ['uri' => 'route:'], - ]); + 'title' => 'This is on the menu', + 'menu_name' => 'main', + 'link' => ['uri' => 'route:'], + ]); $menu_link_content->save(); // Confirm the menu block does include menu section when the menu is not // overridden. - $block = $this->placeBlock('system_menu_block:main'); $menu_block = $this->placeBlock('system_menu_block:main'); + $web_assert->assertWaitOnAjaxRequest(); $this->drupalGet('user'); $this->openBlockForm($this->getBlockSelector($menu_block)); $web_assert->elementExists('css', '#menu-overview'); @@ -647,6 +653,12 @@ public function testOverriddenConfigRemoved() { $this->drupalGet('user'); $this->openBlockForm($this->getBlockSelector($menu_block)); $web_assert->elementNotExists('css', '#menu-overview'); + $page->pressButton('Save Main navigation'); + $this->assertElementVisibleAfterWait('css', 'div:contains(The block configuration has been saved)'); + $web_assert->assertWaitOnAjaxRequest(); + // 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')); } /**