Issue #3186821 by mohit_aghera, Dom., ankithashetty, Kristen Pol: Attribute “hreflang” not allowed on element “span” and “button” at this point

merge-requests/539/head
catch 2021-04-09 13:48:02 +01:00
parent f3674e9b6f
commit 1b0a44154a
2 changed files with 20 additions and 4 deletions

View File

@ -170,13 +170,13 @@ class LinkGenerator implements LinkGeneratorInterface {
}
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);

View File

@ -161,7 +161,7 @@ class LinkGeneratorTest extends UnitTestCase {
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'));
@ -172,6 +172,14 @@ class LinkGeneratorTest extends UnitTestCase {
$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);
}
/**
@ -208,7 +216,7 @@ class LinkGeneratorTest extends UnitTestCase {
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'));
@ -218,6 +226,14 @@ class LinkGeneratorTest extends UnitTestCase {
$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);
}
/**