[BUGFIX] Use SiteLanguage in forms 69/57969/5
authorJulian Wundrak <julian@wundrak.net>
Mon, 3 Sep 2018 07:27:26 +0000 (09:27 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Mon, 3 Sep 2018 18:43:45 +0000 (20:43 +0200)
TranslationService of forms only respect language sets in TypoScript.
Use SiteLanguage is the leading configuration and TypoScript as
fallback.

Resolves: #85909
Releases: master
Change-Id: I961161434e38916e8885af883523eff98f0b467c
Reviewed-on: https://review.typo3.org/57969
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Julian Wundrak <julian@wundrak.net>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/form/Classes/Service/TranslationService.php

index 78de9ae..30ef444 100644 (file)
@@ -15,10 +15,12 @@ namespace TYPO3\CMS\Form\Service;
  * The TYPO3 project - inspiring people to share!
  */
 
+use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Localization\Locales;
 use TYPO3\CMS\Core\Localization\LocalizationFactory;
 use TYPO3\CMS\Core\SingletonInterface;
+use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -575,17 +577,23 @@ class TranslationService implements SingletonInterface
 
         $this->alternativeLanguageKeys = [];
         if (TYPO3_MODE === 'FE') {
-            if (isset($this->getTypoScriptFrontendController()->config['config']['language'])) {
-                $this->languageKey = $this->getTypoScriptFrontendController()->config['config']['language'];
-                if (isset($this->getTypoScriptFrontendController()->config['config']['language_alt'])) {
-                    $this->alternativeLanguageKeys[] = $this->getTypoScriptFrontendController()->config['config']['language_alt'];
-                } else {
-                    /** @var \TYPO3\CMS\Core\Localization\Locales $locales */
-                    $locales = GeneralUtility::makeInstance(Locales::class);
-                    if (in_array($this->languageKey, $locales->getLocales(), true)) {
-                        foreach ($locales->getLocaleDependencies($this->languageKey) as $language) {
-                            $this->alternativeLanguageKeys[] = $language;
-                        }
+            $tsfe = $this->getTypoScriptFrontendController();
+
+            if ($this->getCurrentSiteLanguage() instanceof SiteLanguage) {
+                $this->languageKey = $this->getCurrentSiteLanguage()->getTypo3Language();
+            } elseif (isset($tsfe->config['config']['language'])) {
+                $this->languageKey = $tsfe->config['config']['language'];
+                if (isset($tsfe->config['config']['language_alt'])) {
+                    $this->alternativeLanguageKeys[] = $tsfe->config['config']['language_alt'];
+                }
+            }
+
+            if ($this->languageKey !== 'default' && empty($this->alternativeLanguageKeys)) {
+                /** @var \TYPO3\CMS\Core\Localization\Locales $locales */
+                $locales = GeneralUtility::makeInstance(Locales::class);
+                if (in_array($this->languageKey, $locales->getLocales(), true)) {
+                    foreach ($locales->getLocaleDependencies($this->languageKey) as $language) {
+                        $this->alternativeLanguageKeys[] = $language;
                     }
                 }
             }
@@ -692,6 +700,19 @@ class TranslationService implements SingletonInterface
     }
 
     /**
+     * Returns the currently configured "site language" if a site is configured (= resolved) in the current request.
+     *
+     * @return SiteLanguage|null
+     */
+    protected function getCurrentSiteLanguage(): ?SiteLanguage
+    {
+        if ($GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface) {
+            return $GLOBALS['TYPO3_REQUEST']->getAttribute('language', null);
+        }
+        return null;
+    }
+
+    /**
      * @return LanguageService
      */
     protected function getLanguageService(): LanguageService