summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-11-21 16:26:04 (GMT)
committerAlex Pott2018-11-21 16:26:15 (GMT)
commit37584675424ac5340f68aedffbc70f971798e791 (patch)
treeb39a8377c6eae27c1e9424fc0127b58a391f20f5
parent01a729ab2b261909067b1c55480900b2bd663e7e (diff)
Issue #2948068 by drpal, dawehner, borisson_, ethomas08, lauriii, yoroy, tedbow: Placing and then removing a block appends incorrect query string destination parameter
(cherry picked from commit 44664acfa3a737d0290f48bfaa6b8323aeae965c)
-rw-r--r--core/modules/block/js/block.admin.es6.js3
-rw-r--r--core/modules/block/js/block.admin.js2
-rw-r--r--core/modules/block/src/BlockListBuilder.php17
-rw-r--r--core/modules/block/tests/src/Functional/BlockTest.php24
4 files changed, 44 insertions, 2 deletions
diff --git a/core/modules/block/js/block.admin.es6.js b/core/modules/block/js/block.admin.es6.js
index 197bc4b..ff4d8eb 100644
--- a/core/modules/block/js/block.admin.es6.js
+++ b/core/modules/block/js/block.admin.es6.js
@@ -93,7 +93,8 @@
*/
Drupal.behaviors.blockHighlightPlacement = {
attach(context, settings) {
- if (settings.blockPlacement) {
+ // Ensure that the block we are attempting to scroll to actually exists.
+ if (settings.blockPlacement && $('.js-block-placed').length) {
$(context)
.find('[data-drupal-selector="edit-blocks"]')
.once('block-highlight')
diff --git a/core/modules/block/js/block.admin.js b/core/modules/block/js/block.admin.js
index 7cafed1..641f12d 100644
--- a/core/modules/block/js/block.admin.js
+++ b/core/modules/block/js/block.admin.js
@@ -41,7 +41,7 @@
Drupal.behaviors.blockHighlightPlacement = {
attach: function attach(context, settings) {
- if (settings.blockPlacement) {
+ if (settings.blockPlacement && $('.js-block-placed').length) {
$(context).find('[data-drupal-selector="edit-blocks"]').once('block-highlight').each(function () {
var $container = $(this);
diff --git a/core/modules/block/src/BlockListBuilder.php b/core/modules/block/src/BlockListBuilder.php
index c1ccc50..d2286fc 100644
--- a/core/modules/block/src/BlockListBuilder.php
+++ b/core/modules/block/src/BlockListBuilder.php
@@ -354,6 +354,23 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
if (isset($operations['delete'])) {
$operations['delete']['title'] = $this->t('Remove');
+ // Block operation links should have the `block-placement` query string
+ // parameter removed to ensure that JavaScript does not receive a block
+ // name that has been recently removed.
+ foreach ($operations as $operation) {
+ /** @var \Drupal\Core\Url $url */
+ $url = $operation['url'];
+ $query = $url->getOption('query');
+ $destination = $query['destination'];
+
+ $destinationUrl = Url::fromUserInput($destination);
+ $destinationQuery = $destinationUrl->getOption('query');
+ unset($destinationQuery['block-placement']);
+
+ $destinationUrl->setOption('query', $destinationQuery);
+ $query['destination'] = $destinationUrl->toString();
+ $url->setOption('query', $query);
+ }
}
return $operations;
}
diff --git a/core/modules/block/tests/src/Functional/BlockTest.php b/core/modules/block/tests/src/Functional/BlockTest.php
index 53b4866..9fb3357 100644
--- a/core/modules/block/tests/src/Functional/BlockTest.php
+++ b/core/modules/block/tests/src/Functional/BlockTest.php
@@ -239,6 +239,30 @@ class BlockTest extends BlockTestBase {
}
/**
+ * Tests the block operation links.
+ */
+ public function testBlockOperationLinks() {
+ $this->drupalGet('admin/structure/block');
+ // Go to the select block form.
+ $this->clickLink('Place block');
+ // Select the first available block.
+ $this->clickLink('Place block');
+ // Finally place the block
+ $this->submitForm([], 'Save block');
+
+ $url = $this->getUrl();
+ $parsed = parse_url($url);
+ $this->assertContains('block-placement', $parsed['query']);
+
+ $this->clickLink('Remove');
+ $this->submitForm([], 'Remove');
+
+ $url = $this->getUrl();
+ $parsed = parse_url($url);
+ $this->assertTrue(empty($parsed['query']));
+ }
+
+ /**
* Tests that the block form has a theme selector when not passed via the URL.
*/
public function testBlockThemeSelector() {