[BUGFIX] Initialize language key in AbstractPlugin 18/59018/6
authorGeorg Ringer <georg.ringer@gmail.com>
Mon, 3 Dec 2018 17:52:33 +0000 (18:52 +0100)
committerBenni Mack <benni@typo3.org>
Tue, 4 Dec 2018 05:55:16 +0000 (06:55 +0100)
The AbstractPlugin must check SiteLanguage first for
current language key and use the TypoScript only
as fallback.

Resolves: #87063
Releases: master
Change-Id: I4a4f60c2fb2c759bece2aacc4a287ba006a8165c
Reviewed-on: https://review.typo3.org/59018
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/frontend/Classes/Plugin/AbstractPlugin.php
typo3/sysext/frontend/Tests/Unit/Plugin/AbstractPluginTest.php

index a39bced..34f382e 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Frontend\Plugin;
  */
 
 use Doctrine\DBAL\Driver\Statement;
+use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\QueryHelper;
@@ -22,6 +23,7 @@ use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
 use TYPO3\CMS\Core\Localization\Locales;
 use TYPO3\CMS\Core\Localization\LocalizationFactory;
 use TYPO3\CMS\Core\Service\MarkerBasedTemplateService;
+use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\HttpUtility;
@@ -261,21 +263,25 @@ class AbstractPlugin
                 $this->frontendController->reqCHash();
             }
         }
-        if (!empty($this->frontendController->config['config']['language'])) {
+        $siteLanguage = $this->getCurrentSiteLanguage();
+        if ($siteLanguage) {
+            $this->LLkey = $siteLanguage->getTypo3Language();
+        } elseif (!empty($this->frontendController->config['config']['language'])) {
             $this->LLkey = $this->frontendController->config['config']['language'];
-            if (empty($this->frontendController->config['config']['language_alt'])) {
-                /** @var Locales $locales */
-                $locales = GeneralUtility::makeInstance(Locales::class);
-                if (in_array($this->LLkey, $locales->getLocales())) {
-                    $this->altLLkey = '';
-                    foreach ($locales->getLocaleDependencies($this->LLkey) as $language) {
-                        $this->altLLkey .= $language . ',';
-                    }
-                    $this->altLLkey = rtrim($this->altLLkey, ',');
+        }
+
+        if (empty($this->frontendController->config['config']['language_alt'])) {
+            /** @var Locales $locales */
+            $locales = GeneralUtility::makeInstance(Locales::class);
+            if (in_array($this->LLkey, $locales->getLocales())) {
+                $this->altLLkey = '';
+                foreach ($locales->getLocaleDependencies($this->LLkey) as $language) {
+                    $this->altLLkey .= $language . ',';
                 }
-            } else {
-                $this->altLLkey = $this->frontendController->config['config']['language_alt'];
+                $this->altLLkey = rtrim($this->altLLkey, ',');
             }
+        } else {
+            $this->altLLkey = $this->frontendController->config['config']['language_alt'];
         }
     }
 
@@ -1404,4 +1410,19 @@ class AbstractPlugin
         }
         return $tempArr[$value];
     }
+
+    /**
+     * Returns the currently configured "site language" if a site is configured (= resolved) in the current request.
+     *
+     * @internal
+     */
+    protected function getCurrentSiteLanguage(): ?SiteLanguage
+    {
+        $request = $GLOBALS['TYPO3_REQUEST'] ?? null;
+        return $request
+               && $request instanceof ServerRequestInterface
+               && $request->getAttribute('language') instanceof SiteLanguage
+            ? $request->getAttribute('language')
+            : null;
+    }
 }
index 42e1894..1bc337b 100644 (file)
@@ -37,6 +37,11 @@ class AbstractPluginTest extends UnitTestCase
     protected $defaultPiVars;
 
     /**
+     * @var bool
+     */
+    protected $resetSingletonInstances = true;
+
+    /**
      * Sets up this testcase
      */
     protected function setUp()