[BUGFIX] Use SiteLanguage in LocalizationUtility 97/57697/4
authorGeorg Ringer <georg.ringer@gmail.com>
Thu, 26 Jul 2018 19:15:05 +0000 (21:15 +0200)
committerBenni Mack <benni@typo3.org>
Thu, 30 Aug 2018 19:52:08 +0000 (21:52 +0200)
Check the current site language and use TS as fallback in
the LocalizationUtility

Resolves: #85644
Releases: master
Change-Id: If0e92dc7d8f12755251fc4b8cceb6db155dbf3e2
Reviewed-on: https://review.typo3.org/57697
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Rudy Gnodde <rgn@windinternet.nl>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Daniel Lorenz <daniel.lorenz@extco.de>
Tested-by: Daniel Lorenz <daniel.lorenz@extco.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/extbase/Classes/Utility/LocalizationUtility.php

index 5e8b856..91e583a 100644 (file)
@@ -14,8 +14,10 @@ namespace TYPO3\CMS\Extbase\Utility;
  * The TYPO3 project - inspiring people to share!
  */
 
+use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Localization\Locales;
 use TYPO3\CMS\Core\Localization\LocalizationFactory;
+use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
 use TYPO3\CMS\Extbase\Object\ObjectManager;
@@ -193,17 +195,23 @@ class LocalizationUtility
         ];
         if (TYPO3_MODE === 'FE') {
             $tsfe = static::getTypoScriptFrontendController();
-            if (isset($tsfe->config['config']['language'])) {
+            $siteLanguage = self::getCurrentSiteLanguage();
+
+            // Get values from site language, which takes precedence over TypoScript settings
+            if ($siteLanguage instanceof SiteLanguage) {
+                $languageKeys['languageKey'] = $siteLanguage->getTypo3Language();
+            } elseif (isset($tsfe->config['config']['language'])) {
                 $languageKeys['languageKey'] = $tsfe->config['config']['language'];
                 if (isset($tsfe->config['config']['language_alt'])) {
                     $languageKeys['alternativeLanguageKeys'] = $tsfe->config['config']['language_alt'];
-                } else {
-                    /** @var $locales \TYPO3\CMS\Core\Localization\Locales */
-                    $locales = GeneralUtility::makeInstance(Locales::class);
-                    if (in_array($languageKeys['languageKey'], $locales->getLocales())) {
-                        foreach ($locales->getLocaleDependencies($languageKeys['languageKey']) as $language) {
-                            $languageKeys['alternativeLanguageKeys'] = $language;
-                        }
+                }
+            }
+
+            if (empty($languageKeys['alternativeLanguageKeys'])) {
+                $locales = GeneralUtility::makeInstance(Locales::class);
+                if (in_array($languageKeys['languageKey'], $locales->getLocales())) {
+                    foreach ($locales->getLocaleDependencies($languageKeys['languageKey']) as $language) {
+                        $languageKeys['alternativeLanguageKeys'] = $language;
                     }
                 }
             }
@@ -303,6 +311,20 @@ class LocalizationUtility
     }
 
     /**
+     * Returns the currently configured "site language" if a site is configured (= resolved)
+     * in the current request.
+     *
+     * @return SiteLanguage|null
+     */
+    protected static function getCurrentSiteLanguage(): ?SiteLanguage
+    {
+        if ($GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface) {
+            return $GLOBALS['TYPO3_REQUEST']->getAttribute('language', null);
+        }
+        return null;
+    }
+
+    /**
      * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
      */
     protected static function getTypoScriptFrontendController()