Commit 5489967f authored by Georg Ringer's avatar Georg Ringer
Browse files

[BUGFIX] Set property hreflang of SiteLanguage to empty string

By defining `$hreflang` of SiteLanguage to an empty string instead of
'en-US' wrong hreflang tags are avoided in the frontend.

Even though the field is set to required there are usecases where this
field is not set, e.g. by changing the site configuration manually. This
would have lead to hreflang tags pointing to a valid site but with a
wrong hreflang information.

Resolves: #92418
Releases: master
Change-Id: I042c275a2b107cac48a877c7e4043f69e378347d
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65888

Tested-by: Richard Haeser's avatarRichard Haeser <richard@richardhaeser.com>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarMartin Kutschker <mkutschker-typo3@yahoo.com>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Richard Haeser's avatarRichard Haeser <richard@richardhaeser.com>
Reviewed-by: default avatarGuido Schmechel <guido.schmechel@brandung.de>
Reviewed-by: default avatarMartin Kutschker <mkutschker-typo3@yahoo.com>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
parent 111b47c9
......@@ -81,7 +81,7 @@ class SiteLanguage
*
* @var string
*/
protected $hreflang = 'en-US';
protected $hreflang = '';
/**
* The direction for this language
......
......@@ -97,7 +97,7 @@ class SiteLanguageTest extends UnitTestCase
'title' => 'Default',
'websiteTitle' => '',
'twoLetterIsoCode' => 'en',
'hreflang' => 'en-US',
'hreflang' => '',
'direction' => '',
'typo3Language' => 'default',
'flagIdentifier' => '',
......
......@@ -61,7 +61,7 @@ class HrefLangGenerator
/** @var SiteLanguage $siteLanguage */
$siteLanguage = $event->getRequest()->getAttribute('language');
foreach ($languages['languagemenu'] as $language) {
if ($language['available'] === 1 && !empty($language['link'])) {
if ($language['available'] === 1 && !empty($language['link']) && $language['hreflang']) {
$href = $this->getAbsoluteUrl($language['link'], $siteLanguage);
$hrefLangs[$language['hreflang']] = $href;
}
......
......@@ -36,9 +36,11 @@ entities:
language:
- self: {id: 1, title: 'German', code: 'de'}
- self: {id: 2, title: 'Swiss German', code: 'de'}
- self: {id: 3, title: 'Dutch', code: 'nl'}
page:
- self: {id: *idAcmeRootPage, title: 'EN: Root', root: true, slug: '/'}
children:
- self: {id: 1100, title: 'EN: Welcome', slug: '/hello'}
languageVariants:
- self: {id: 1101, title: 'DE: Willkommen', language: 1, slug: '/willkommen'}
- self: {id: 1102, title: 'NL: Welkom', language: 3, slug: '/welkom'}
......@@ -43,6 +43,7 @@ class HrefLangGeneratorTest extends FunctionalTestCase
protected const LANGUAGE_PRESETS = [
'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8', 'iso' => 'en', 'hrefLang' => 'en-US', 'direction' => ''],
'DE' => ['id' => 1, 'title' => 'German', 'locale' => 'de_DE.UTF8', 'iso' => 'de', 'hrefLang' => 'de-DE', 'direction' => ''],
'NL' => ['id' => 3, 'title' => 'Dutch', 'locale' => 'nl_NL.UTF8', 'iso' => 'nl', 'hrefLang' => '', 'direction' => ''],
];
public static function setUpBeforeClass(): void
......@@ -67,6 +68,7 @@ class HrefLangGeneratorTest extends FunctionalTestCase
[
$this->buildDefaultLanguageConfiguration('EN', '/'),
$this->buildLanguageConfiguration('DE', '/de'),
$this->buildLanguageConfiguration('NL', '/nl'),
]
);
......@@ -134,6 +136,30 @@ class HrefLangGeneratorTest extends FunctionalTestCase
],
[]
],
'English page, with German and Dutch translation, without Dutch hreflang config' => [
'https://acme.com/hello',
[
'<link rel="alternate" hreflang="en-US" href="https://acme.com/hello"/>',
'<link rel="alternate" hreflang="de-DE" href="https://acme.com/de/willkommen"/>',
'<link rel="alternate" hreflang="x-default" href="https://acme.com/hello"/>',
],
[
'<link rel="alternate" hreflang="en-US" href="https://acme.com/nl/welkom"/>',
'<link rel="alternate" hreflang="" href="https://acme.com/nl/welkom"/>',
]
],
'Dutch page, with German and English translation, without Dutch hreflang config' => [
'https://acme.com/hello',
[
'<link rel="alternate" hreflang="en-US" href="https://acme.com/hello"/>',
'<link rel="alternate" hreflang="de-DE" href="https://acme.com/de/willkommen"/>',
'<link rel="alternate" hreflang="x-default" href="https://acme.com/hello"/>',
],
[
'<link rel="alternate" hreflang="en-US" href="https://acme.com/nl/welkom"/>',
'<link rel="alternate" hreflang="" href="https://acme.com/nl/welkom"/>',
]
],
];
}
......
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