summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Rowlands2018-10-26 06:33:00 (GMT)
committerLee Rowlands2018-10-26 06:33:51 (GMT)
commit83e35e57aa764125cf564aeec93be77f8d3943de (patch)
treeb000ece53c3b868babfd00b609ce9f7286730d27
parentf5d796a303cc3e0e84016f8541c3be4a5cb77af7 (diff)
Issue #2707879 by hctom, Sam152, grahl, reekris, casey, gngn, Noemi, dawehner, jherencia: Contextual Links do not respect pathPrefix
(cherry picked from commit 12c3109341a03ee5534a25dadb885e52cfa1be22)
-rw-r--r--core/modules/contextual/js/contextual.es6.js2
-rw-r--r--core/modules/contextual/js/contextual.js2
-rw-r--r--core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php15
-rw-r--r--core/modules/settings_tray/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php3
-rw-r--r--core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php3
5 files changed, 21 insertions, 4 deletions
diff --git a/core/modules/contextual/js/contextual.es6.js b/core/modules/contextual/js/contextual.es6.js
index f52059a..2b26ee2 100644
--- a/core/modules/contextual/js/contextual.es6.js
+++ b/core/modules/contextual/js/contextual.es6.js
@@ -99,7 +99,7 @@
// Set the destination parameter on each of the contextual links.
const destination = `destination=${Drupal.encodePath(
- drupalSettings.path.currentPath,
+ Drupal.url(drupalSettings.path.currentPath),
)}`;
$contextual.find('.contextual-links a').each(function() {
const url = this.getAttribute('href');
diff --git a/core/modules/contextual/js/contextual.js b/core/modules/contextual/js/contextual.js
index d51eba2..6264b74 100644
--- a/core/modules/contextual/js/contextual.js
+++ b/core/modules/contextual/js/contextual.js
@@ -55,7 +55,7 @@
$contextual.html(html).addClass('contextual').prepend(Drupal.theme('contextualTrigger'));
- var destination = 'destination=' + Drupal.encodePath(drupalSettings.path.currentPath);
+ var destination = 'destination=' + Drupal.encodePath(Drupal.url(drupalSettings.path.currentPath));
$contextual.find('.contextual-links a').each(function () {
var url = this.getAttribute('href');
var glue = url.indexOf('?') === -1 ? '?' : '&';
diff --git a/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php b/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php
index 7435dad..29d2ec7 100644
--- a/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php
+++ b/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php
@@ -92,4 +92,19 @@ class ContextualLinksTest extends WebDriverTestBase {
$this->assertSession()->pageTextContains('Everything is contextual!');
}
+ /**
+ * Test the contextual links destination.
+ */
+ public function testContextualLinksDestination() {
+ $this->grantPermissions(Role::load(Role::AUTHENTICATED_ID), [
+ 'access contextual links',
+ 'administer blocks',
+ ]);
+ $this->drupalGet('user');
+ $this->assertSession()->waitForElement('css', '.contextual button');
+ $expected_destination_value = (string) $this->loggedInUser->toUrl()->toString();
+ $contextual_link_url_parsed = parse_url($this->getSession()->getPage()->findLink('Configure block')->getAttribute('href'));
+ $this->assertEquals("destination=$expected_destination_value", $contextual_link_url_parsed['query']);
+ }
+
}
diff --git a/core/modules/settings_tray/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php b/core/modules/settings_tray/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php
index 6f623cb..a543baf 100644
--- a/core/modules/settings_tray/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php
+++ b/core/modules/settings_tray/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php
@@ -145,7 +145,8 @@ class QuickEditIntegrationTest extends SettingsTrayTestBase {
$href = array_search('Quick edit', $link_labels);
$this->assertEquals('', $href);
$href = array_search('Quick edit settings', $link_labels);
- $this->assertTrue(strstr($href, '/admin/structure/block/manage/custom/settings-tray?destination=user/2') !== FALSE);
+ $destination = (string) $this->loggedInUser->toUrl()->toString();
+ $this->assertTrue(strstr($href, "/admin/structure/block/manage/custom/settings-tray?destination=$destination") !== FALSE);
}
/**
diff --git a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php
index 0e6b9d6..d505a0b 100644
--- a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php
+++ b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php
@@ -69,7 +69,8 @@ class SettingsTrayBlockFormTest extends SettingsTrayTestBase {
$link = $web_assert->waitForElement('css', "$block_selector .contextual-links li a");
$this->assertEquals('Quick edit', $link->getHtml(), "'Quick edit' is the first contextual link for the block.");
- $this->assertContains("/admin/structure/block/manage/$block_id/settings-tray?destination=user/2", $link->getAttribute('href'));
+ $destination = (string) $this->loggedInUser->toUrl()->toString();
+ $this->assertContains("/admin/structure/block/manage/$block_id/settings-tray?destination=$destination", $link->getAttribute('href'));
if (isset($toolbar_item)) {
// Check that you can open a toolbar tray and it will be closed after