TYPO3 CMS  TYPO3_8-7
DatabaseSystemLanguageRows.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 
28 {
36  public function addData(array $result)
37  {
38  $languageService = $this->getLanguageService();
39 
40  $pageTs = $result['pageTsConfig'];
41  $defaultLanguageLabel = $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage');
42  if (isset($pageTs['mod.']['SHARED.']['defaultLanguageLabel'])) {
43  $defaultLanguageLabel = $pageTs['mod.']['SHARED.']['defaultLanguageLabel'] . ' (' . $languageService->sL($defaultLanguageLabel) . ')';
44  }
45  $defaultLanguageFlag = 'empty-empty';
46  if (isset($pageTs['mod.']['SHARED.']['defaultLanguageFlag'])) {
47  $defaultLanguageFlag = 'flags-' . $pageTs['mod.']['SHARED.']['defaultLanguageFlag'];
48  }
49 
50  $languageRows = [
51  -1 => [
52  // -1: "All" languages
53  'uid' => -1,
54  'title' => $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:multipleLanguages'),
55  // Same as for 0, but iso is used in flex form context only and duplication handled there
56  // @todo: Maybe drop this if flex form language handling is extracted?
57  'iso' => 'DEF',
58  'flagIconIdentifier' => 'flags-multiple',
59  ],
60  0 => [
61  // 0: "Default" language
62  'uid' => 0,
63  'title' => $defaultLanguageLabel,
64  // Default "DEF" is a fallback preparation for flex form iso codes "lDEF"
65  // @todo: Maybe drop this if flex form language handling is extracted?
66  'iso' => 'DEF',
67  'flagIconIdentifier' => $defaultLanguageFlag,
68  ],
69  ];
70 
71  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
72  ->getQueryBuilderForTable('sys_language');
73 
74  $queryBuilder->getRestrictions()->removeAll();
75 
76  $queryResult = $queryBuilder
77  ->select('uid', 'title', 'language_isocode', 'flag')
78  ->from('sys_language')
79  ->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)))
80  ->orderBy('sorting')
81  ->execute();
82 
83  while ($row = $queryResult->fetch()) {
84  $uid = $row['uid'];
85  $languageRows[$uid] = [
86  'uid' => $uid,
87  'title' => $row['title'],
88  'flagIconIdentifier' => 'flags-' . $row['flag'],
89  ];
90  if (!empty($row['language_isocode'])) {
91  $languageRows[$uid]['iso'] = $row['language_isocode'];
92  } else {
93  // No iso code could be found. This is currently possible in the system but discouraged.
94  // So, code within FormEngine has to be suited to work with an empty iso code. However,
95  // it may impact certain multi language scenarios, so we add a flash message hinting for
96  // incomplete configuration here.
97  // It might be possible to convert this to a non-catchable exception later if
98  // it iso code is enforced on a different layer of the system (tca required + migration wizard).
99  // @todo: This could be relaxed again if flex form language handling is extracted,
100  // @todo: since the rest of the FormEngine code does not rely on iso code?
101  $message = sprintf(
102  $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:error.missingLanguageIsocode'),
103  $row['title'],
104  $uid
105  );
107  $flashMessage = GeneralUtility::makeInstance(
108  FlashMessage::class,
109  $message,
110  '',
112  );
114  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
115  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
116  $defaultFlashMessageQueue->enqueue($flashMessage);
117  $languageRows[$uid]['iso'] = '';
118  }
119  }
120 
121  $result['systemLanguageRows'] = $languageRows;
122 
123  return $result;
124  }
125 
129  protected function getLanguageService()
130  {
131  return $GLOBALS['LANG'];
132  }
133 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']