Loading core/lib/Drupal/Core/Utility/LinkGenerator.php +2 −2 Original line number Diff line number Diff line Loading @@ -170,13 +170,13 @@ public function generate($text, Url $url) { } if ($url->isRouted() && $url->getRouteName() === '<nolink>') { $generated_link = new GeneratedNoLink(); unset($attributes['href']); unset($attributes['href'], $attributes['hreflang']); return $this->doGenerate($generated_link, $attributes, $variables); } if ($url->isRouted() && $url->getRouteName() === '<button>') { $generated_link = new GeneratedButton(); $attributes['type'] = 'button'; unset($attributes['href']); unset($attributes['href'], $attributes['hreflang']); return $this->doGenerate($generated_link, $attributes, $variables); } $generated_url = $url->toString(TRUE); Loading core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php +18 −2 Original line number Diff line number Diff line Loading @@ -161,7 +161,7 @@ public function testGenerate() { public function testGenerateNoLink() { $this->urlGenerator->expects($this->never()) ->method('generateFromRoute'); $this->moduleHandler->expects($this->once()) $this->moduleHandler->expects($this->exactly(2)) ->method('alter') ->with('link', $this->isType('array')); Loading @@ -172,6 +172,14 @@ public function testGenerateNoLink() { $result = $this->linkGenerator->generate('Test', $url); $this->assertInstanceOf(GeneratedNoLink::class, $result); $this->assertSame('<span>Test</span>', (string) $result); // Validate removal of hreflang attributes. $url = Url::fromRoute('<nolink>', [], [ 'language' => new Language(['id' => 'de']), ]); $url->setUrlGenerator($this->urlGenerator); $result = $this->linkGenerator->generate('Test With Language', $url); $this->assertSame('<span>Test With Language</span>', (string) $result); } /** Loading Loading @@ -208,7 +216,7 @@ public function testGenerateNone() { public function testGenerateButton() { $this->urlGenerator->expects($this->never()) ->method('generateFromRoute'); $this->moduleHandler->expects($this->once()) $this->moduleHandler->expects($this->exactly(2)) ->method('alter') ->with('link', $this->isType('array')); Loading @@ -218,6 +226,14 @@ public function testGenerateButton() { $result = $this->linkGenerator->generate('Test', $url); $this->assertInstanceOf(GeneratedButton::class, $result); $this->assertSame('<button type="button">Test</button>', (string) $result); // Validate removal of hreflang attributes. $url = new Url('<button>', [], [ 'language' => new Language(['id' => 'de']), ]); $url->setUrlGenerator($this->urlGenerator); $result = $this->linkGenerator->generate('Test With Language', $url); $this->assertSame('<button type="button">Test With Language</button>', (string) $result); } /** Loading Loading
core/lib/Drupal/Core/Utility/LinkGenerator.php +2 −2 Original line number Diff line number Diff line Loading @@ -170,13 +170,13 @@ public function generate($text, Url $url) { } if ($url->isRouted() && $url->getRouteName() === '<nolink>') { $generated_link = new GeneratedNoLink(); unset($attributes['href']); unset($attributes['href'], $attributes['hreflang']); return $this->doGenerate($generated_link, $attributes, $variables); } if ($url->isRouted() && $url->getRouteName() === '<button>') { $generated_link = new GeneratedButton(); $attributes['type'] = 'button'; unset($attributes['href']); unset($attributes['href'], $attributes['hreflang']); return $this->doGenerate($generated_link, $attributes, $variables); } $generated_url = $url->toString(TRUE); Loading
core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php +18 −2 Original line number Diff line number Diff line Loading @@ -161,7 +161,7 @@ public function testGenerate() { public function testGenerateNoLink() { $this->urlGenerator->expects($this->never()) ->method('generateFromRoute'); $this->moduleHandler->expects($this->once()) $this->moduleHandler->expects($this->exactly(2)) ->method('alter') ->with('link', $this->isType('array')); Loading @@ -172,6 +172,14 @@ public function testGenerateNoLink() { $result = $this->linkGenerator->generate('Test', $url); $this->assertInstanceOf(GeneratedNoLink::class, $result); $this->assertSame('<span>Test</span>', (string) $result); // Validate removal of hreflang attributes. $url = Url::fromRoute('<nolink>', [], [ 'language' => new Language(['id' => 'de']), ]); $url->setUrlGenerator($this->urlGenerator); $result = $this->linkGenerator->generate('Test With Language', $url); $this->assertSame('<span>Test With Language</span>', (string) $result); } /** Loading Loading @@ -208,7 +216,7 @@ public function testGenerateNone() { public function testGenerateButton() { $this->urlGenerator->expects($this->never()) ->method('generateFromRoute'); $this->moduleHandler->expects($this->once()) $this->moduleHandler->expects($this->exactly(2)) ->method('alter') ->with('link', $this->isType('array')); Loading @@ -218,6 +226,14 @@ public function testGenerateButton() { $result = $this->linkGenerator->generate('Test', $url); $this->assertInstanceOf(GeneratedButton::class, $result); $this->assertSame('<button type="button">Test</button>', (string) $result); // Validate removal of hreflang attributes. $url = new Url('<button>', [], [ 'language' => new Language(['id' => 'de']), ]); $url->setUrlGenerator($this->urlGenerator); $result = $this->linkGenerator->generate('Test With Language', $url); $this->assertSame('<button type="button">Test With Language</button>', (string) $result); } /** Loading