Commit 9526bb82 authored by catch's avatar catch

Issue #2081963 by mr.baileys, dawehner: Shortcut add/remove link on titles...

Issue #2081963 by mr.baileys, dawehner: Shortcut add/remove link on titles don't work on route only pages.
parent ec06f877
......@@ -165,16 +165,24 @@ public function testNoShortcutLink() {
->save();
$this->drupalGet('page-that-does-not-exist');
$this->assertNoRaw('add-shortcut', 'Add to shortcuts link was not shown on a page not found.');
$result = $this->xpath('//div[contains(@class, "add-shortcut")]');
$this->assertTrue(empty($result), 'Add to shortcuts link was not shown on a page not found.');
// The user does not have access to this path.
$this->drupalGet('admin/modules');
$this->assertNoRaw('add-shortcut', 'Add to shortcuts link was not shown on a page the user does not have access to.');
$result = $this->xpath('//div[contains(@class, "add-shortcut")]');
$this->assertTrue(empty($result), 'Add to shortcuts link was not shown on a page the user does not have access to.');
// Verify that the testing mechanism works by verifying the shortcut
// link appears on admin/people.
$this->drupalGet('admin/people');
$this->assertRaw('remove-shortcut', 'Remove from shortcuts link was shown on a page the user does have access to.');
$result = $this->xpath('//div[contains(@class, "remove-shortcut")]');
$this->assertTrue(!empty($result), 'Remove from shortcuts link was shown on a page the user does have access to.');
// Verify that the shortcut link appears on routing only pages.
$this->drupalGet('router_test/test2');
$result = $this->xpath('//div[contains(@class, "add-shortcut")]');
$this->assertTrue(!empty($result), 'Add to shortcuts link was shown on a page the user does have access to.');
}
}
......@@ -8,6 +8,7 @@
use Drupal\Core\Routing\UrlMatcher;
use Drupal\Core\Url;
use Drupal\shortcut\ShortcutSetInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -388,7 +389,17 @@ function shortcut_preprocess_page(&$variables) {
// shortcuts and if the page's actual content is being shown (for example,
// we do not want to display it on "access denied" or "page not found"
// pages).
if (shortcut_set_edit_access() && ($item = menu_get_item()) && $item['access']) {
// Load the router item corresponding to the current page.
$request = \Drupal::request();
$item = array();
if ($route = $request->attributes->get(RouteObjectInterface::ROUTE_NAME)) {
$item['href'] = $request->attributes->get('_system_path');
// @todo What should be done on a 404/403 page?
$item['access'] = TRUE;
}
if (shortcut_set_edit_access() && !empty($item['access'])) {
$link = current_path();
if (!($url = Url::createFromPath($link))) {
// Bail out early if we couldn't find a matching route.
......
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