[BUGFIX] Set correct language uids in MenuProcessor when set to auto 76/58576/3
authorNikita Hovratov <nikita.h@live.de>
Thu, 4 Oct 2018 14:45:14 +0000 (16:45 +0200)
committerBenni Mack <benni@typo3.org>
Sun, 28 Oct 2018 11:33:04 +0000 (12:33 +0100)
The configuration special.auto was introduced in #84775. The function
MenuProcessor->prepareLevelLanguageConfiguration() was not aware of that
and set the value for the languageUids to "auto".

Resolves: #86571
Releases: master
Change-Id: I6e6aedd351077b7e1ac49ed5bd7facab48590014
Reviewed-on: https://review.typo3.org/58576
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Jasmina Ließmann <code@frauliessmann.de>
Tested-by: Jasmina Ließmann <code@frauliessmann.de>
Reviewed-by: Joerg Kummer <typo3@enobe.de>
Tested-by: Joerg Kummer <typo3@enobe.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/frontend/Classes/DataProcessing/MenuProcessor.php

index 258ab62..ccb8ec9 100644 (file)
@@ -14,10 +14,13 @@ namespace TYPO3\CMS\Frontend\DataProcessing;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Routing\SiteMatcher;
+use TYPO3\CMS\Core\Site\Entity\SiteInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
 /**
  * This menu processor utilizes HMENU to generate a json encoded menu
@@ -322,6 +325,11 @@ class MenuProcessor implements DataProcessorInterface
     public function prepareLevelLanguageConfiguration()
     {
         if ($this->menuConfig['special'] === 'language') {
+            $languageUids = $this->menuConfig['special.']['value'];
+            if ($this->menuConfig['special.']['value'] === 'auto') {
+                $site = $this->getCurrentSite();
+                $languageUids = implode(',', array_keys($site->getLanguages()));
+            }
             $this->menuLevelConfig['stdWrap.']['cObject.'] = array_replace_recursive(
                 $this->menuLevelConfig['stdWrap.']['cObject.'],
                 [
@@ -332,7 +340,7 @@ class MenuProcessor implements DataProcessorInterface
                     ],
                     '70' => 'TEXT',
                     '70.' => [
-                        'value' => $this->menuConfig['special.']['value'],
+                        'value' => $languageUids,
                         'listNum.' => [
                             'stdWrap.' => [
                                 'data' => 'register:count_HMENU_MENUOBJ',
@@ -518,4 +526,24 @@ class MenuProcessor implements DataProcessorInterface
 
         return $menuItem;
     }
+
+    /**
+     * Returns the currently configured "site" if a site is configured (= resolved) in the current request.
+     *
+     * @return SiteInterface
+     * @throws \TYPO3\CMS\Core\Exception\SiteNotFoundException
+     */
+    protected function getCurrentSite(): SiteInterface
+    {
+        $matcher = GeneralUtility::makeInstance(SiteMatcher::class);
+        return $matcher->matchByPageId((int)$this->getTypoScriptFrontendController()->id);
+    }
+
+    /**
+     * @return TypoScriptFrontendController
+     */
+    protected function getTypoScriptFrontendController()
+    {
+        return $GLOBALS['TSFE'];
+    }
 }