diff --git a/core/modules/settings_tray/js/settings_tray.es6.js b/core/modules/settings_tray/js/settings_tray.es6.js index ea8f570464..6487690c7b 100644 --- a/core/modules/settings_tray/js/settings_tray.es6.js +++ b/core/modules/settings_tray/js/settings_tray.es6.js @@ -5,7 +5,7 @@ * @private */ -(($, Drupal, { settings_tray: settings }) => { +(($, Drupal) => { const blockConfigureSelector = '[data-settings-tray-edit]'; const toggleEditSelector = '[data-drupal-settingstray="toggle"]'; const itemsToToggleSelector = '[data-off-canvas-main-canvas], #toolbar-bar, [data-drupal-settingstray="editable"] a, [data-drupal-settingstray="editable"] button'; @@ -169,16 +169,6 @@ if (!instance.options.data.hasOwnProperty('dialogOptions')) { instance.options.data.dialogOptions = {}; } - - if (settings && settings.hasOwnProperty('overridden_blocks')) { - Object.keys(settings.overridden_blocks).forEach((blockId) => { - // @see Route entity.block.off_canvas_form - if (instance.options.url.indexOf(`/admin/structure/block/manage/${blockId}/off-canvas`) !== -1) { - instance.options.url = settings.overridden_blocks[blockId]; - } - }); - } - instance.options.data.dialogOptions.settingsTrayActiveEditableId = $(instance.element).parents('.settings-tray-editable').attr('id'); instance.progress = { type: 'fullscreen' }; }); @@ -268,4 +258,4 @@ } }, }); -})(jQuery, Drupal, drupalSettings); +})(jQuery, Drupal); diff --git a/core/modules/settings_tray/js/settings_tray.js b/core/modules/settings_tray/js/settings_tray.js index 9d3da50afe..7a83e156ca 100644 --- a/core/modules/settings_tray/js/settings_tray.js +++ b/core/modules/settings_tray/js/settings_tray.js @@ -5,9 +5,7 @@ * @preserve **/ -(function ($, Drupal, _ref) { - var settings = _ref.settings_tray; - +(function ($, Drupal) { var blockConfigureSelector = '[data-settings-tray-edit]'; var toggleEditSelector = '[data-drupal-settingstray="toggle"]'; var itemsToToggleSelector = '[data-off-canvas-main-canvas], #toolbar-bar, [data-drupal-settingstray="editable"] a, [data-drupal-settingstray="editable"] button'; @@ -102,15 +100,6 @@ if (!instance.options.data.hasOwnProperty('dialogOptions')) { instance.options.data.dialogOptions = {}; } - - if (settings && settings.hasOwnProperty('overridden_blocks')) { - Object.keys(settings.overridden_blocks).forEach(function (blockId) { - if (instance.options.url.indexOf('/admin/structure/block/manage/' + blockId + '/off-canvas') !== -1) { - instance.options.url = settings.overridden_blocks[blockId]; - } - }); - } - instance.options.data.dialogOptions.settingsTrayActiveEditableId = $(instance.element).parents('.settings-tray-editable').attr('id'); instance.progress = { type: 'fullscreen' }; }); @@ -164,4 +153,4 @@ } } }); -})(jQuery, Drupal, drupalSettings); \ No newline at end of file +})(jQuery, Drupal); \ No newline at end of file diff --git a/core/modules/settings_tray/settings_tray.libraries.yml b/core/modules/settings_tray/settings_tray.libraries.yml index 11b55a478f..de5c82c78d 100644 --- a/core/modules/settings_tray/settings_tray.libraries.yml +++ b/core/modules/settings_tray/settings_tray.libraries.yml @@ -17,4 +17,3 @@ drupal.settings_tray: - core/drupal - core/jquery.once - core/drupal.ajax - - core/drupalSettings diff --git a/core/modules/settings_tray/settings_tray.module b/core/modules/settings_tray/settings_tray.module index 5186f73599..d73ca617bf 100644 --- a/core/modules/settings_tray/settings_tray.module +++ b/core/modules/settings_tray/settings_tray.module @@ -11,8 +11,7 @@ use Drupal\settings_tray\Form\SystemBrandingOffCanvasForm; use Drupal\settings_tray\Form\SystemMenuOffCanvasForm; use Drupal\block\BlockInterface; -use Drupal\Core\Url; -use Drupal\Core\EventSubscriber\MainContentViewSubscriber; +use Drupal\block\Entity\Block; /** * Implements hook_help(). @@ -76,29 +75,6 @@ function settings_tray_block_view_alter(array &$build) { $build['#contextual_links']['settings_tray'] = [ 'route_parameters' => [], ]; - // If a block currently has configuration overrides it cannot be edited in the - // Settings Tray form. - if (_settings_tray_has_block_overrides($build['#block'])) { - // The URL query options should use the off-canvas dialog and add the - // current page destination. - $query = [ - MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_dialog.off_canvas', - ] + \Drupal::destination()->getAsArray(); - - $url = Url::fromRoute('settings_tray.overridden_block_warning') - ->setRouteParameter('block', $build['#block']->id()) - ->setOptions(['query' => $query]); - - // Store the URL to the overridden notice for this block in drupalSettings. - // This will be used in the Javascript function prepareAjaxLinks() to - // replace the URL to the Settings Tray edit form. We cannot use - // settings_tray_contextual_links_view_alter() to alter the URL because the - // contextual links will not be rebuilt for every context that could have - // configuration overrides. - $build['#attached']['drupalSettings']['settings_tray']['overridden_blocks'][$build['#block']->id()] = $url->toString(); - $generated_url = $url->toString(TRUE); - \Drupal::service('renderer')->addCacheableDependency($build, $generated_url); - } } /** @@ -231,3 +207,15 @@ function settings_tray_css_alter(&$css, AttachedAssetsInterface $assets) { $css[$path]['group'] = 200; } } + +/** + * Implements hook_contextual_links_alter(). + */ +function settings_tray_contextual_links_alter(array &$links, $group, array $route_parameters) { + 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_warning'; + } + } +} diff --git a/core/modules/settings_tray/src/Controller/OverriddenBlockConfig.php b/core/modules/settings_tray/src/Controller/OverriddenBlockConfig.php index 7706cce0a2..50efd38d7c 100644 --- a/core/modules/settings_tray/src/Controller/OverriddenBlockConfig.php +++ b/core/modules/settings_tray/src/Controller/OverriddenBlockConfig.php @@ -13,7 +13,7 @@ * because there is no uniform method for editing any potential configuration * override. * - * @see settings_tray_block_view_alter(). + * @see settings_tray_block_view_alter() */ class OverriddenBlockConfig { diff --git a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php index 2feb1c4771..98e8c59497 100644 --- a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php +++ b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php @@ -44,6 +44,7 @@ class SettingsTrayBlockFormTest extends OffCanvasTestBase { // cause test failures. 'settings_tray_test_css', 'settings_tray_test', + 'settings_tray_override_test', ]; /** @@ -588,14 +589,13 @@ 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.'; - $this->container->get('module_installer')->install(['settings_tray_override_test']); // 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'); // Confirm the label is actually overridden. $web_assert->elementContains('css', $this->getBlockCssSelector($overridden_block), 'Now this will be the label.'); @@ -607,7 +607,7 @@ public function testOverriddenDisabled() { $block = $this->placeBlock('system_powered_by_block', [ 'label_display' => 1, 'label' => 'Labely label', - ]); + ]); $this->drupalGet('user'); // Confirm the label is not overridden. $web_assert->elementContains('css', $this->getBlockCssSelector($block), 'Labely label');