diff --git a/core/modules/settings_tray/settings_tray.module b/core/modules/settings_tray/settings_tray.module index 5415ab319b..834c6f4515 100644 --- a/core/modules/settings_tray/settings_tray.module +++ b/core/modules/settings_tray/settings_tray.module @@ -9,10 +9,12 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Drupal\settings_tray\Block\BlockEntityOffCanvasForm; +use \Drupal\settings_tray\Form\BlockFormWithRelatedConfigInterface; use Drupal\settings_tray\Form\SystemBrandingOffCanvasForm; use Drupal\settings_tray\Form\SystemMenuOffCanvasForm; use Drupal\block\BlockInterface; use Drupal\block\Entity\Block; +use \Drupal\Core\Plugin\PluginWithFormsInterface; /** * Implements hook_help(). @@ -68,7 +70,18 @@ function settings_tray_contextual_links_view_alter(&$element, $items) { * @internal */ function _settings_tray_has_block_overrides(BlockInterface $block) { - return \Drupal::config($block->getEntityType()->getConfigPrefix() . '.' . $block->id())->hasOverrides(); + $has_overrides = \Drupal::config($block->getEntityType()->getConfigPrefix() . '.' . $block->id())->hasOverrides(); + if (!$has_overrides) { + // Check if the related config has overriddes + $block_plugin = $block->getPlugin(); + if ($block_plugin instanceof PluginWithFormsInterface) { + $settings_tray_form = Drupal::service('plugin_form.factory')->createInstance($block_plugin, 'settings_tray', 'configure'); + if($settings_tray_form instanceof BlockFormWithRelatedConfigInterface) { + $has_overrides = $settings_tray_form->hasOverriddenConfig(); + } + } + } + return $has_overrides; } /** diff --git a/core/modules/settings_tray/src/Form/BlockFormWithRelatedConfigInterface.php b/core/modules/settings_tray/src/Form/BlockFormWithRelatedConfigInterface.php new file mode 100644 index 0000000000..9ae4dc6720 --- /dev/null +++ b/core/modules/settings_tray/src/Form/BlockFormWithRelatedConfigInterface.php @@ -0,0 +1,19 @@ +plugin->submitConfigurationForm($form, $form_state); } + /** + * {@inheritdoc} + */ + public function hasOverriddenConfig() { + $config = $this->configFactory->get('system.site'); + return $config->hasOverrides('name') || $config->hasOverrides('slogan'); + } } diff --git a/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php b/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php index 15d19a87f9..3d202b6651 100644 --- a/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php +++ b/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php @@ -22,7 +22,7 @@ * * @internal */ -class SystemMenuOffCanvasForm extends PluginFormBase implements ContainerInjectionInterface { +class SystemMenuOffCanvasForm extends PluginFormBase implements ContainerInjectionInterface, BlockFormWithRelatedConfigInterface { use StringTranslationTrait; use RedirectDestinationTrait; @@ -150,4 +150,11 @@ public function setPlugin(PluginInspectionInterface $plugin) { $this->menu = $this->menuStorage->load($this->plugin->getDerivativeId()); } + /** + * {@inheritdoc} + */ + public function hasOverriddenConfig() { + return \Drupal::config($this->menu->getEntityType()->getConfigPrefix() . '.' . $this->menu->id())->hasOverrides(); + } + } 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 0184a9e533..1171a1bb90 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 @@ -21,6 +21,11 @@ public function loadOverrides($names) { if (in_array('block.block.overridden_block', $names)) { $overrides = $overrides + ['block.block.overridden_block' => ['settings' => ['label' => 'Now this will be the label.']]]; } + if (in_array('system.site', $names)) { + if ($site_name = \Drupal::state()->get('settings_tray_override_test.site_name')) { + $overrides = $overrides + ['system.site' => ['name' => $site_name]]; + } + } return $overrides; } diff --git a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php index 0550f57843..c308d0edc3 100644 --- a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php +++ b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php @@ -588,24 +588,13 @@ protected function getTestThemes() { public function testOverriddenDisabled() { $web_assert = $this->assertSession(); $page = $this->getSession()->getPage(); - // Test a overridden block does not show the form in the off-canvas dialog. - // @see \Drupal\settings_tray_override_test\ConfigOverrider $overridden_block = $this->placeBlock('system_powered_by_block', [ 'id' => 'overridden_block', 'label_display' => 1, 'label' => 'This will be overridden.', ]); $this->drupalGet('user'); - $block_selector = $this->getBlockSelector($overridden_block); - $block_id = $overridden_block->id(); - // Confirm the label is actually overridden. - $web_assert->elementContains('css', $block_selector, 'Now this will be the label.'); - // Confirm the block does not have a quick edit link. - foreach ($page->findAll('css', "$block_selector .contextual-links li a") as $link) { - $this->assertNotContains("/admin/structure/block/manage/$block_id/off-canvas", $link->getAttribute('href')); - } - // Confirm the block is not marked as Settings Tray editable. - $this->assertFalse($page->find('css', $block_selector)->hasAttribute('data-drupal-settingstray')); + $this->assertOverriddenBlockDisabled($overridden_block, 'Now this will be the label.'); // Test a non-overridden block does show the form in the off-canvas dialog. $block = $this->placeBlock('system_powered_by_block', [ @@ -620,6 +609,40 @@ public function testOverriddenDisabled() { $web_assert->elementContains('css', $block_selector, 'Labely label'); $this->enableEditMode(); $this->openBlockForm($this->getBlockSelector($block)); + + // Confirm the branding block is disabled when site name is overridden. + $overridden_name = 'The namey name'; + $this->container->get('state')->set('settings_tray_override_test.site_name', $overridden_name); + $overridden_branding_block = $this->placeBlock('system_branding_block'); + $this->drupalGet('user'); + $this->assertOverriddenBlockDisabled($overridden_branding_block, $overridden_name); + } + + /** + * Asserts that an overridden block has Settings Tray disabled. + * + * @param \Drupal\block\Entity\Block $overridden_block + * The overridden block. + * @param string $override_text + * The override text that should appear in the block. + */ + protected function assertOverriddenBlockDisabled(Block $overridden_block, $override_text) { + $web_assert = $this->assertSession(); + $page = $this->getSession()->getPage(); + $block_selector = $this->getBlockSelector($overridden_block); + $block_id = $overridden_block->id(); + // Confirm the block does not have a quick edit link. + $contextual_links = $page->findAll('css', "$block_selector .contextual-links li a"); + $this->assertNotEmpty($contextual_links); + foreach ($contextual_links as $link) { + $this->assertNotContains("/admin/structure/block/manage/$block_id/off-canvas", $link->getAttribute('href')); + } + // Confirm the block is not marked as Settings Tray editable. + $this->assertFalse($page->find('css', $block_selector) + ->hasAttribute('data-drupal-settingstray')); + + // Confirm the text is actually overridden. + $web_assert->elementContains('css', $this->getBlockSelector($overridden_block), $override_text); } }