summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2019-01-02 09:56:15 (GMT)
committerNathaniel Catchpole2019-01-02 09:56:37 (GMT)
commit597d991559cccc7b2d04c23845e4b6ac2af46164 (patch)
treefd8162abeefd3cb3c77b7b4a839f8eeb47a84d6a
parentb6e5032aba2a0caaba91b4398a0a5aec1211704c (diff)
Issue #3018942 by welly, alexpott, jibran, Krzysztof DomaƄski, floydm: Domain URL language detection - InvalidArgumentException: The user-entered string must begin with a '/', '?', or '#'
(cherry picked from commit 79e94b49b36df4a2c9d5eaf8636502a6fe9e4479)
-rw-r--r--core/modules/block/src/BlockListBuilder.php23
-rw-r--r--core/modules/block/tests/src/Functional/BlockTest.php24
-rw-r--r--core/modules/block/tests/src/Functional/BlockUiTest.php45
3 files changed, 45 insertions, 47 deletions
diff --git a/core/modules/block/src/BlockListBuilder.php b/core/modules/block/src/BlockListBuilder.php
index d2286fc..3884d27 100644
--- a/core/modules/block/src/BlockListBuilder.php
+++ b/core/modules/block/src/BlockListBuilder.php
@@ -193,6 +193,9 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
if ($this->request->query->has('block-placement')) {
$placement = $this->request->query->get('block-placement');
$form['#attached']['drupalSettings']['blockPlacement'] = $placement;
+ // Remove the block placement from the current request so that it is not
+ // passed on to any redirect destinations.
+ $this->request->query->remove('block-placement');
}
// Loop over each region and build blocks.
@@ -354,23 +357,6 @@ 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;
}
@@ -395,9 +381,6 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
$entity->save();
}
$this->messenger->addStatus($this->t('The block settings have been updated.'));
-
- // Remove any previously set block placement.
- $this->request->query->remove('block-placement');
}
/**
diff --git a/core/modules/block/tests/src/Functional/BlockTest.php b/core/modules/block/tests/src/Functional/BlockTest.php
index 9fb3357..53b4866 100644
--- a/core/modules/block/tests/src/Functional/BlockTest.php
+++ b/core/modules/block/tests/src/Functional/BlockTest.php
@@ -239,30 +239,6 @@ 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() {
diff --git a/core/modules/block/tests/src/Functional/BlockUiTest.php b/core/modules/block/tests/src/Functional/BlockUiTest.php
index 2b79260..a2b53e8 100644
--- a/core/modules/block/tests/src/Functional/BlockUiTest.php
+++ b/core/modules/block/tests/src/Functional/BlockUiTest.php
@@ -3,6 +3,8 @@
namespace Drupal\Tests\block\Functional;
use Drupal\Component\Utility\Html;
+use Drupal\language\Entity\ConfigurableLanguage;
+use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use Drupal\Tests\BrowserTestBase;
/**
@@ -288,6 +290,24 @@ class BlockUiTest extends BrowserTestBase {
* Tests the block placement indicator.
*/
public function testBlockPlacementIndicator() {
+ // Test the block placement indicator with using the domain as URL language
+ // indicator. This causes destination query parameters to be absolute URLs.
+ \Drupal::service('module_installer')->install(['language', 'locale']);
+ $this->container = \Drupal::getContainer();
+ ConfigurableLanguage::createFromLangcode('it')->save();
+ $config = $this->config('language.types');
+ $config->set('negotiation.language_interface.enabled', [
+ LanguageNegotiationUrl::METHOD_ID => -10,
+ ]);
+ $config->save();
+ $config = $this->config('language.negotiation');
+ $config->set('url.source', LanguageNegotiationUrl::CONFIG_DOMAIN);
+ $config->set('url.domains', [
+ 'en' => \Drupal::request()->getHost(),
+ 'it' => 'it.example.com',
+ ]);
+ $config->save();
+
// Select the 'Powered by Drupal' block to be placed.
$block = [];
$block['id'] = strtolower($this->randomMachineName());
@@ -296,11 +316,30 @@ class BlockUiTest extends BrowserTestBase {
// After adding a block, it will indicate which block was just added.
$this->drupalPostForm('admin/structure/block/add/system_powered_by_block', $block, t('Save block'));
- $this->assertUrl('admin/structure/block/list/classy?block-placement=' . Html::getClass($block['id']));
+ $this->assertSession()->addressEquals('admin/structure/block/list/classy?block-placement=' . Html::getClass($block['id']));
- // Resaving the block page will remove the block indicator.
+ // Resaving the block page will remove the block placement indicator.
$this->drupalPostForm(NULL, [], t('Save blocks'));
- $this->assertUrl('admin/structure/block/list/classy');
+ $this->assertSession()->addressEquals('admin/structure/block/list/classy');
+
+ // Place another block and test the remove functionality works with the
+ // block placement indicator. Click the first 'Place block' link to bring up
+ // the list of blocks to place in the first available region.
+ $this->clickLink('Place block');
+ // Select the first available block.
+ $this->clickLink('Place block');
+ $block = [];
+ $block['id'] = strtolower($this->randomMachineName());
+ $block['theme'] = 'classy';
+ $this->submitForm([], 'Save block');
+ $this->assertSession()->addressEquals('admin/structure/block/list/classy?block-placement=' . Html::getClass($block['id']));
+
+ // Removing a block will remove the block placement indicator.
+ $this->clickLink('Remove');
+ $this->submitForm([], 'Remove');
+ // @todo https://www.drupal.org/project/drupal/issues/2980527 this should be
+ // 'admin/structure/block/list/classy' but there is a bug.
+ $this->assertSession()->addressEquals('admin/structure/block');
}
/**