[BUGFIX] Populate href lang URI only if the link is available 50/60350/5
authorJulian Wundrak <julian@wundrak.net>
Thu, 28 Mar 2019 20:11:03 +0000 (21:11 +0100)
committerRichard Haeser <richard@maxserv.com>
Fri, 12 Apr 2019 18:33:38 +0000 (20:33 +0200)
If there are e.g., records that have no translation, the
HrefLangGenerator outputs the site-base URL. Expected is that the entry
for this page is suppressed.

Change-Id: I6fbd4dd00955906dff13c0e5aceea6804c52dd1b
Resolves: #88032
Releases: master, 9.5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60350
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Jörg Bösche <typo3@joergboesche.de>
Tested-by: Richard Haeser <richard@maxserv.com>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Richard Haeser <richard@maxserv.com>
typo3/sysext/seo/Classes/HrefLang/HrefLangGenerator.php

index 7eea1f5..e8f3751 100644 (file)
@@ -73,7 +73,7 @@ class HrefLangGenerator
             $languageMenu = GeneralUtility::makeInstance(LanguageMenuProcessor::class);
             $languages = $languageMenu->process($this->cObj, [], [], []);
             foreach ($languages['languagemenu'] as $language) {
-                if ($language['available'] === 1) {
+                if ($language['available'] === 1 && !empty($language['link'])) {
                     $href = $this->getAbsoluteUrl($language['link']);
                     $hreflangs[] =
                         '<link rel="alternate" hreflang="' . htmlspecialchars($language['hreflang']) . '" href="' . htmlspecialchars($href) . '"/>';
@@ -85,7 +85,7 @@ class HrefLangGenerator
                 $hreflangs[] =
                     '<link rel="alternate" hreflang="x-default" href="' . htmlspecialchars($href) . '"/>' . LF;
 
-                $GLOBALS['TSFE']->additionalHeaderData[] = implode(LF, $hreflangs);
+                $this->getTypoScriptFrontendController()->additionalHeaderData[] = implode(LF, $hreflangs);
             }
         }