Commit 597d9915 authored by catch's avatar catch

Issue #3018942 by welly, alexpott, jibran, Krzysztof Domański, floydm: Domain...

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 79e94b49)
parent b6e5032a
......@@ -193,6 +193,9 @@ protected function buildBlocksForm() {
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 @@ 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;
}
......@@ -395,9 +381,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$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');
}
/**
......
......@@ -238,30 +238,6 @@ 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.
*/
......
......@@ -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 @@ public function testMachineNameSuggestion() {
* 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 @@ public function testBlockPlacementIndicator() {
// 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');
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment