Skip to content
Snippets Groups Projects
Unverified Commit c1cc0d5c authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2945033 by longwave, yobottehg, TMWagner, vdsh, jlatorre, catch:...

Issue #2945033 by longwave, yobottehg, TMWagner, vdsh, jlatorre, catch: HtmlHeadLink processing does not allow for duplicated alternate hreflang links

(cherry picked from commit 8f497e0a)
parent c051ff75
No related branches found
No related tags found
5 merge requests!10011Issue #3200534 by quietone, longwave, Kristen Pol: Use dataprovider for...,!2571Issue #3000717: Missing mapping for "nodereference_url" widget,!2521Issue #3185775: Place Views preview on the side on large monitors,!1479Issue #3250298: Return empty string "" with JSON Serializer instead of FALSE,!1478Issue #3250298: Return empty string "" with JSON Serializer instead of FALSE
......@@ -436,7 +436,15 @@ protected function processHtmlHeadLink(array $html_head_link) {
'#attributes' => $attributes,
];
$href = $attributes['href'];
$attached['html_head'][] = [$element, 'html_head_link:' . $attributes['rel'] . ':' . $href];
$rel = $attributes['rel'];
// Allow multiple hreflang tags to use the same href.
if (isset($attributes['hreflang'])) {
$attached['html_head'][] = [$element, 'html_head_link:' . $rel . ':' . $attributes['hreflang'] . ':' . $href];
}
else {
$attached['html_head'][] = [$element, 'html_head_link:' . $rel . ':' . $href];
}
if ($should_add_header) {
// Also add a HTTP header "Link:".
......
......@@ -80,6 +80,7 @@ public function htmlHeaderLink() {
$render['#attached']['html_head_link'][] = [['href' => '/foo?bar=<baz>&baz=false', 'rel' => 'alternate'], TRUE];
$render['#attached']['html_head_link'][] = [['href' => '/not-added-to-http-headers', 'rel' => 'alternate'], FALSE];
$render['#attached']['html_head_link'][] = [['href' => '/foo/bar', 'hreflang' => 'nl', 'rel' => 'alternate'], TRUE];
$render['#attached']['html_head_link'][] = [['href' => '/foo/bar', 'hreflang' => 'de', 'rel' => 'alternate'], TRUE];
return $render;
}
......
......@@ -65,8 +65,13 @@ public function testAttachments() {
$expected_link_headers = [
'</foo?bar=&lt;baz&gt;&amp;baz=false>; rel="alternate"',
'</foo/bar>; hreflang="nl"; rel="alternate"',
'</foo/bar>; hreflang="de"; rel="alternate"',
];
$this->assertEquals($expected_link_headers, $this->getSession()->getResponseHeaders()['Link']);
// Check that duplicate alternate URLs with different hreflangs are allowed.
$test_link = $this->xpath('//head/link[@rel="alternate"][@href="/foo/bar"]');
$this->assertEquals(2, count($test_link), 'Duplicate alternate URLs are allowed.');
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment