Skip to content
Snippets Groups Projects
Unverified Commit 44664acf authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2948068 by drpal, dawehner, borisson_, ethomas08, lauriii, yoroy,...

Issue #2948068 by drpal, dawehner, borisson_, ethomas08, lauriii, yoroy, tedbow: Placing and then removing a block appends incorrect query string destination parameter
parent 53c24728
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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')
......
......@@ -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);
......
......@@ -354,6 +354,23 @@ public function getDefaultOperations(EntityInterface $entity) {
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;
}
......
......@@ -238,6 +238,30 @@ public function testBlock() {
$this->assertNoRaw($block->id());
}
/**
* 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.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment