TYPO3 CMS  TYPO3_7-6
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 
25 
30 {
38  public function addData(array $result)
39  {
40  $database = $this->getDatabase();
41  $languageService = $this->getLanguageService();
42 
43  $pageTs = $result['pageTsConfig'];
44  $defaultLanguageLabel = $languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage');
45  if (isset($pageTs['mod.']['SHARED.']['defaultLanguageLabel'])) {
46  $defaultLanguageLabel = $pageTs['mod.']['SHARED.']['defaultLanguageLabel'] . ' (' . $languageService->sL($defaultLanguageLabel) . ')';
47  }
48  $defaultLanguageFlag = 'empty-empty';
49  if (isset($pageTs['mod.']['SHARED.']['defaultLanguageFlag'])) {
50  $defaultLanguageFlag = 'flags-' . $pageTs['mod.']['SHARED.']['defaultLanguageFlag'];
51  }
52 
53  $languageRows = [
54  -1 => [
55  // -1: "All" languages
56  'uid' => -1,
57  'title' => $languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:multipleLanguages'),
58  // Same as for 0, but iso is used in flex form context only and duplication handled there
59  // @todo: Maybe drop this if flex form language handling is extracted?
60  'iso' => 'DEF',
61  'flagIconIdentifier' => 'flags-multiple',
62  ],
63  0 => [
64  // 0: "Default" language
65  'uid' => 0,
66  'title' => $defaultLanguageLabel,
67  // Default "DEF" is a fallback preparation for flex form iso codes "lDEF"
68  // @todo: Maybe drop this if flex form language handling is extracted?
69  'iso' => 'DEF',
70  'flagIconIdentifier' => $defaultLanguageFlag,
71  ],
72  ];
73 
74  $dbRows = $database->exec_SELECTgetRows(
75  'uid,title,language_isocode,static_lang_isocode,flag',
76  'sys_language',
77  'pid=0'
78  );
79 
80  if ($dbRows === null) {
81  throw new \UnexpectedValueException(
82  'Database query error ' . $database->sql_error(),
83  1438170741
84  );
85  }
86 
87  $isStaticInfoTablesLoaded = ExtensionManagementUtility::isLoaded('static_info_tables');
88  foreach ($dbRows as $dbRow) {
89  $uid = $dbRow['uid'];
90  $languageRows[$uid] = [
91  'uid' => $uid,
92  'title' => $dbRow['title'],
93  'flagIconIdentifier' => 'flags-' . $dbRow['flag'],
94  ];
95  if (!empty($dbRow['language_isocode'])) {
96  $languageRows[$uid]['iso'] = $dbRow['language_isocode'];
97  } elseif ($isStaticInfoTablesLoaded && !empty($dbRow['static_lang_isocode'])) {
99  'Usage of the field "static_lang_isocode" is discouraged, and will stop working with CMS 8. Use the built-in'
100  . ' language field "language_isocode" in your sys_language records.'
101  );
102  $lg_iso_2 = BackendUtility::getRecord('static_languages', $dbRow['static_lang_isocode'], 'lg_iso_2');
103  if ($lg_iso_2['lg_iso_2']) {
104  $languageRows[$uid]['iso'] = $lg_iso_2['lg_iso_2'];
105  }
106  } else {
107  // No iso code could be found. This is currently possible in the system but discouraged.
108  // So, code within FormEngine has to be suited to work with an empty iso code. However,
109  // it may impact certain multi language scenarios, so we add a flash message hinting for
110  // incomplete configuration here.
111  // It might be possible to convert this to a non-catchable exception later if
112  // it iso code is enforced on a different layer of the system (tca required + migration wizard).
113  // @todo: This could be relaxed again if flex form language handling is extracted,
114  // @todo: since the rest of the FormEngine code does not rely on iso code?
115  $message = sprintf(
116  $languageService->sL('LLL:EXT:lang/locallang_core.xlf:error.missingLanguageIsocode'),
117  $dbRow['title'],
118  $uid
119  );
121  $flashMessage = GeneralUtility::makeInstance(
122  FlashMessage::class,
123  $message,
124  '',
126  );
128  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
129  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
130  $defaultFlashMessageQueue->enqueue($flashMessage);
131  $languageRows[$uid]['iso'] = '';
132  }
133  }
134 
135  $result['systemLanguageRows'] = $languageRows;
136 
137  return $result;
138  }
139 
143  protected function getDatabase()
144  {
145  return $GLOBALS['TYPO3_DB'];
146  }
147 
151  protected function getLanguageService()
152  {
153  return $GLOBALS['LANG'];
154  }
155 }
$database
Definition: server.php:40
$uid
Definition: server.php:38
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']