diff --git a/core/modules/settings_tray/js/settings_tray.es6.js b/core/modules/settings_tray/js/settings_tray.es6.js index c182a873ed..a50f45198d 100644 --- a/core/modules/settings_tray/js/settings_tray.es6.js +++ b/core/modules/settings_tray/js/settings_tray.es6.js @@ -166,10 +166,10 @@ } if (drupalSettings.hasOwnProperty('settings_tray') && drupalSettings.settings_tray.hasOwnProperty('overridden_blocks')) { - Object.entries(drupalSettings.settings_tray.overridden_blocks).forEach( - ([blockId, url]) => { - if (instance.options.url.includes(`/${blockId}/`)) { - instance.options.url = url; + Object.keys(drupalSettings.settings_tray.overridden_blocks).forEach( + (blockId) => { + if (instance.options.url.indexOf(`/admin/structure/block/manage/${blockId}/off-canvas`) !== -1) { + instance.options.url = drupalSettings.settings_tray.overridden_blocks[blockId]; } }, ); diff --git a/core/modules/settings_tray/js/settings_tray.js b/core/modules/settings_tray/js/settings_tray.js index 98e81f3d93..9d7e80a1bf 100644 --- a/core/modules/settings_tray/js/settings_tray.js +++ b/core/modules/settings_tray/js/settings_tray.js @@ -4,7 +4,6 @@ * https://www.drupal.org/node/2815083 * @preserve **/ -var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); (function ($, Drupal, drupalSettings) { var blockConfigureSelector = '[data-settings-tray-edit]'; @@ -103,13 +102,9 @@ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = [ } if (drupalSettings.hasOwnProperty('settings_tray') && drupalSettings.settings_tray.hasOwnProperty('overridden_blocks')) { - Object.entries(drupalSettings.settings_tray.overridden_blocks).forEach(function (_ref) { - var _ref2 = _slicedToArray(_ref, 2), - blockId = _ref2[0], - url = _ref2[1]; - - if (instance.options.url.includes('/' + blockId + '/')) { - instance.options.url = url; + Object.keys(drupalSettings.settings_tray.overridden_blocks).forEach(function (blockId) { + if (instance.options.url.indexOf('/admin/structure/block/manage/' + blockId + '/off-canvas') !== -1) { + instance.options.url = drupalSettings.settings_tray.overridden_blocks[blockId]; } }); } diff --git a/core/modules/settings_tray/tests/modules/settings_tray_override_test/settings_tray_override_test.info.yml b/core/modules/settings_tray/tests/modules/settings_tray_override_test/settings_tray_override_test.info.yml new file mode 100644 index 0000000000..39fb56fa55 --- /dev/null +++ b/core/modules/settings_tray/tests/modules/settings_tray_override_test/settings_tray_override_test.info.yml @@ -0,0 +1,8 @@ +name: 'Configuration override test for Settings Tray' +type: module +package: Testing +version: VERSION +core: 8.x + +dependencies: + - settings_tray diff --git a/core/modules/settings_tray/tests/modules/settings_tray_override_test/settings_tray_override_test.services.yml b/core/modules/settings_tray/tests/modules/settings_tray_override_test/settings_tray_override_test.services.yml new file mode 100644 index 0000000000..b23035bde2 --- /dev/null +++ b/core/modules/settings_tray/tests/modules/settings_tray_override_test/settings_tray_override_test.services.yml @@ -0,0 +1,5 @@ +services: + settings_tray_override_test.overrider: + class: Drupal\settings_tray_override_test\ConfigOverrider + tags: + - { name: config.factory.override} 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 new file mode 100644 index 0000000000..1ee59631c5 --- /dev/null +++ b/core/modules/settings_tray/tests/modules/settings_tray_override_test/src/ConfigOverrider.php @@ -0,0 +1,51 @@ + ['settings' => ['label' => 'ALL YOUR LABELS BELONG TO US']]]; + } + } + return $overrides; + } + + /** + * {@inheritdoc} + */ + public function getCacheSuffix() { + return 'ConfigOverrider'; + } + + /** + * {@inheritdoc} + */ + public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) { + return NULL; + } + + /** + * {@inheritdoc} + */ + public function getCacheableMetadata($name) { + return new CacheableMetadata(); + } + +} diff --git a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php index fcfecde400..5480fd512b 100644 --- a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php +++ b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php @@ -2,6 +2,7 @@ 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; @@ -75,7 +76,7 @@ public function testBlocks($theme, $block_plugin, $new_page_text, $element_selec $page = $this->getSession()->getPage(); $this->enableTheme($theme); $block = $this->placeBlock($block_plugin); - $block_selector = str_replace('_', '-', $this->getBlockSelector($block)); + $block_selector = $this->getBlockCssSelector($block); $block_id = $block->id(); $this->drupalGet('user'); @@ -267,8 +268,10 @@ protected function assertOffCanvasBlockFormIsValid() { * @param string $contextual_link_container * The element that contains the contextual links. If none provide the * $block_selector will be used. + * @param bool $confirm_form + * Determines if the block form should be confirmed. */ - protected function openBlockForm($block_selector, $contextual_link_container = '') { + protected function openBlockForm($block_selector, $contextual_link_container = '', $confirm_form = TRUE) { if (!$contextual_link_container) { $contextual_link_container = $block_selector; } @@ -283,7 +286,10 @@ protected function openBlockForm($block_selector, $contextual_link_container = ' $this->assertSession()->assertWaitOnAjaxRequest(); $this->click($block_selector); $this->waitForOffCanvasToOpen(); - $this->assertOffCanvasBlockFormIsValid(); + if ($confirm_form) { + $this->assertOffCanvasBlockFormIsValid(); + } + } /** @@ -321,7 +327,7 @@ public function testQuickEditLinks() { $this->enableTheme($theme); $block = $this->placeBlock($block_plugin); - $block_selector = str_replace('_', '-', $this->getBlockSelector($block)); + $block_selector = $this->getBlockCssSelector($block); // Load the same page twice. foreach ([1, 2] as $page_load_times) { $this->drupalGet('node/' . $node->id()); @@ -577,4 +583,52 @@ protected function getTestThemes() { }); } + /** + * Tests that the blocks with configuration overrides are disabled. + */ + 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), 'ALL YOUR LABELS BELONG TO US'); + $this->enableEditMode(); + $this->openBlockForm($this->getBlockCssSelector($overridden_block), '', FALSE); + $web_assert->elementContains('css', self::OFF_CANVAS_CSS_SELECTOR, $overridden_text); + + // Test a non-overridden block does show the form in the off-canvas dialog. + $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'); + $this->openBlockForm($this->getBlockCssSelector($block)); + $web_assert->elementNotContains('css', self::OFF_CANVAS_CSS_SELECTOR, $overridden_text); + } + + /** + * Gets the CSS selector for a block. + * + * @param \Drupal\block\BlockInterface $block + * The block. + * + * @return string + * The CSS selector for the block. + */ + protected function getBlockCssSelector(BlockInterface $block) { + return str_replace('_', '-', $this->getBlockSelector($block)); + } + } diff --git a/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTestBase.php b/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTestBase.php index d3f446cf6a..63d97badb9 100644 --- a/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTestBase.php +++ b/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTestBase.php @@ -9,6 +9,11 @@ */ abstract class OffCanvasTestBase extends JavascriptTestBase { + /** + * CSS select for the Off-canvas dialog. + */ + const OFF_CANVAS_CSS_SELECTOR = '.ui-dialog[aria-describedby="drupal-off-canvas"]'; + /** * {@inheritdoc} */ @@ -83,7 +88,7 @@ protected function waitForOffCanvasToClose() { * @return \Behat\Mink\Element\NodeElement|null */ protected function getOffCanvasDialog() { - $off_canvas_dialog = $this->getSession()->getPage()->find('css', '.ui-dialog[aria-describedby="drupal-off-canvas"]'); + $off_canvas_dialog = $this->getSession()->getPage()->find('css', self::OFF_CANVAS_CSS_SELECTOR); $this->assertEquals(FALSE, empty($off_canvas_dialog), 'The off-canvas dialog was found.'); return $off_canvas_dialog; }