Unverified Commit 8e678056 authored by alexpott's avatar alexpott

Issue #2838351 by Leon Kessler, LaravZ, Eyal Shalev, andypost: Links with no...

Issue #2838351 by Leon Kessler, LaravZ, Eyal Shalev, andypost: Links with no path get active class on front page
parent 2ddb3983
......@@ -133,8 +133,15 @@ public function generate($text, Url $url) {
if ($url->isRouted() && !isset($variables['options']['attributes']['data-drupal-link-system-path'])) {
// @todo System path is deprecated - use the route name and parameters.
$system_path = $url->getInternalPath();
// Special case for the front page.
$variables['options']['attributes']['data-drupal-link-system-path'] = $system_path == '' ? '<front>' : $system_path;
if ($url->getRouteName() === '<front>') {
$system_path = '<front>';
}
if (!empty($system_path)) {
$variables['options']['attributes']['data-drupal-link-system-path'] = $system_path;
}
}
}
......
......@@ -152,6 +152,9 @@ public function testGenerate() {
/**
* Tests the generate() method with the <nolink> route.
*
* The set_active_class option is set to TRUE to ensure we do not get the
* active class and the data-drupal-link-system-path attribute.
*
* @covers ::generate
*/
public function testGenerateNoLink() {
......@@ -163,12 +166,39 @@ public function testGenerateNoLink() {
$url = Url::fromRoute('<nolink>');
$url->setUrlGenerator($this->urlGenerator);
$url->setOption('set_active_class', TRUE);
$result = $this->linkGenerator->generate('Test', $url);
$this->assertTrue($result instanceof GeneratedNoLink);
$this->assertSame('<span>Test</span>', (string) $result);
}
/**
* Tests the generate() method with the <none> route.
*
* The set_active_class option is set to TRUE to ensure we do not get the
* active class and the data-drupal-link-system-path attribute.
*
* @covers ::generate
*/
public function testGenerateNone() {
$this->urlGenerator->expects($this->once())
->method('generateFromRoute')
->with('<none>', [], ['set_active_class' => TRUE] + $this->defaultOptions)
->willReturn((new GeneratedUrl())->setGeneratedUrl(''));
$this->moduleHandler->expects($this->once())
->method('alter')
->with('link', $this->isType('array'));
$url = Url::fromRoute('<none>');
$url->setUrlGenerator($this->urlGenerator);
$url->setOption('set_active_class', TRUE);
$result = $this->linkGenerator->generate('Test', $url);
$this->assertSame('<a href="">Test</a>', (string) $result);
}
/**
* Tests the generate() method with an external URL.
*
......
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