[BUGFIX] Use SiteFinder in SearchController for getting all languages 37/60337/4
authorGeorg Ringer <georg.ringer@gmail.com>
Mon, 25 Mar 2019 20:59:25 +0000 (21:59 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 5 Apr 2019 15:50:08 +0000 (17:50 +0200)
The SiteFinder must be used instead of only fetching all languages from
sys_language.

Resolves: #87999
Releases: master, 9.5
Change-Id: I95432c6221a8ee06d1fbb45a6780b0ec7c80ddf4
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60337
Tested-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/indexed_search/Classes/Controller/SearchController.php

index f3e0491..17c0187 100644 (file)
@@ -1101,23 +1101,23 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
     protected function getAllAvailableLanguageOptions()
     {
         $allOptions = [
-            '-1' => LocalizationUtility::translate('languageUids.-1', 'IndexedSearch'),
-            '0' => LocalizationUtility::translate('languageUids.0', 'IndexedSearch')
+            '-1' => LocalizationUtility::translate('languageUids.-1', 'IndexedSearch')
         ];
         $blindSettings = $this->settings['blind'];
         if (!$blindSettings['languageUid']) {
-            // Add search languages
-            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
-                ->getQueryBuilderForTable('sys_language');
-            $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
-            $result = $queryBuilder
-                ->select('uid', 'title')
-                ->from('sys_language')
-                ->execute();
-
-            while ($lang = $result->fetch()) {
-                $allOptions[$lang['uid']] = $lang['title'];
+            try {
+                $site = GeneralUtility::makeInstance(SiteFinder::class)
+                    ->getSiteByPageId($GLOBALS['TSFE']->id);
+
+                $languages = $site->getLanguages();
+                foreach ($languages as $language) {
+                    $allOptions[$language->getLanguageId()] = $language->getNavigationTitle() ?? $language->getTitle();
+                }
+            } catch (SiteNotFoundException $e) {
+                // No Site or pseudo site found, no options
+                $allOptions = [];
             }
+
             // disable single entries by TypoScript
             $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['languageUid']);
         } else {