diff --git a/core/modules/settings_tray/settings_tray.module b/core/modules/settings_tray/settings_tray.module index 64e6df6737..5415ab319b 100644 --- a/core/modules/settings_tray/settings_tray.module +++ b/core/modules/settings_tray/settings_tray.module @@ -110,10 +110,14 @@ function settings_tray_preprocess_block(&$variables) { $block_plugin_manager = \Drupal::service('plugin.manager.block'); /** @var \Drupal\Core\Block\BlockPluginInterface $block_plugin */ $block_plugin = $block_plugin_manager->createInstance($variables['plugin_id']); - if ($access_checker->accessBlockPlugin($block_plugin)->isAllowed()) { - // Add class and attributes to all blocks to allow Javascript to target. - $variables['attributes']['class'][] = 'settings-tray-editable'; - $variables['attributes']['data-drupal-settingstray'] = 'editable'; + if (!empty($variables['elements']['#contextual_links']['block']['route_parameters']['block'])) { + $block_id = $variables['elements']['#contextual_links']['block']['route_parameters']['block']; + $block = Block::load($block_id); + if ($access_checker->accessBlockPlugin($block_plugin)->isAllowed() && !_settings_tray_has_block_overrides($block)) { + // Add class and attributes to all blocks to allow Javascript to target. + $variables['attributes']['class'][] = 'settings-tray-editable'; + $variables['attributes']['data-drupal-settingstray'] = 'editable'; + } } } @@ -221,7 +225,7 @@ function settings_tray_contextual_links_alter(array &$links, $group, array $rout if (isset($links['settings_tray.block_configure']['route_parameters']['block'])) { $block = Block::load($links['settings_tray.block_configure']['route_parameters']['block']); if (_settings_tray_has_block_overrides($block)) { - $links['settings_tray.block_configure']['route_name'] = 'settings_tray.overridden_block_notice'; + unset($links['settings_tray.block_configure']); } } } diff --git a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php index e1f76eb269..0550f57843 100644 --- a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php +++ b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\settings_tray\FunctionalJavascript; -use Drupal\block\BlockInterface; use Drupal\block\Entity\Block; use Drupal\block_content\Entity\BlockContent; use Drupal\block_content\Entity\BlockContentType; @@ -588,7 +587,7 @@ protected function getTestThemes() { */ public function testOverriddenDisabled() { $web_assert = $this->assertSession(); - $overridden_text = 'This block cannot be edited in the Settings Tray form because it has configuration overrides in effect.'; + $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', [ @@ -597,11 +596,16 @@ public function testOverriddenDisabled() { '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', $this->getBlockSelector($overridden_block), 'Now this will be the label.'); - $this->enableEditMode(); - $this->openBlockForm($this->getBlockSelector($overridden_block), '', FALSE); - $web_assert->elementContains('css', self::OFF_CANVAS_CSS_SELECTOR, $overridden_text); + $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')); // Test a non-overridden block does show the form in the off-canvas dialog. $block = $this->placeBlock('system_powered_by_block', [ @@ -609,10 +613,13 @@ public function testOverriddenDisabled() { 'label' => 'Labely label', ]); $this->drupalGet('user'); + $block_selector = $this->getBlockSelector($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', $this->getBlockSelector($block), 'Labely label'); + $web_assert->elementContains('css', $block_selector, 'Labely label'); + $this->enableEditMode(); $this->openBlockForm($this->getBlockSelector($block)); - $web_assert->elementNotContains('css', self::OFF_CANVAS_CSS_SELECTOR, $overridden_text); } }