62adf4ba3b0291fabc97d5cb1efb96c364bc91ff
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FormDataProvider / DatabaseSystemLanguageRows.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form\FormDataProvider;
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
17 use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Core\Database\DatabaseConnection;
20 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * Fill the "systemLanguageRows" part of the result array
25 */
26 class DatabaseSystemLanguageRows implements FormDataProviderInterface {
27
28 /**
29 * Fetch available system languages and resolve iso code if necessary.
30 *
31 * @todo: This is similar to what TranslationConfigurationProvider->getSystemLanguages() does,
32 * @todo: use the method as soon as bugs have been fixed in there.
33 *
34 * @param array $result
35 * @return array
36 * @throws \UnexpectedValueException
37 */
38 public function addData(array $result) {
39 $database = $this->getDatabase();
40
41 $languageRows = [
42 0 => [
43 'uid' => 0,
44 'title' => 'Default Language',
45 // Default "DEF" is a fallback preparation for flex form iso codes "lDEF"
46 'iso' => 'DEF',
47 ],
48 ];
49
50 $dbRows = $database->exec_SELECTgetRows(
51 'uid,title,language_isocode,static_lang_isocode',
52 'sys_language',
53 'pid=0 AND hidden=0'
54 );
55
56 if ($dbRows === NULL) {
57 throw new \UnexpectedValueException(
58 'Database query error ' . $database->sql_error(),
59 1438170741
60 );
61 }
62
63 $isStaticInfoTablesLoaded = ExtensionManagementUtility::isLoaded('static_info_tables');
64 foreach ($dbRows as $dbRow) {
65 if (!empty($dbRow['language_isocode'])) {
66 $dbRow['iso'] = $dbRow['language_isocode'];
67 } elseif ($isStaticInfoTablesLoaded && !empty($dbRow['static_lang_isocode'])) {
68 GeneralUtility::deprecationLog(
69 'Usage of the field "static_lang_isocode" is discouraged, and will stop working with CMS 8. Use the built-in'
70 . ' language field "language_isocode" in your sys_language records.'
71 );
72 $lg_iso_2 = BackendUtility::getRecord('static_languages', $dbRow['static_lang_isocode'], 'lg_iso_2');
73 if ($lg_iso_2['lg_iso_2']) {
74 $dbRow['iso'] = $lg_iso_2['lg_iso_2'];
75 }
76 } else {
77 // @todo: Not having iso code at all is maybe a bad idea ... throw an exception instead?
78 $dbRow['iso'] = '';
79 }
80 unset($dbRow['language_isocode']);
81 unset($dbRow['static_lang_isocode']);
82 $languageRows[(int)$dbRow['uid']] = $dbRow;
83 }
84
85 $result['systemLanguageRows'] = $languageRows;
86
87 return $result;
88 }
89
90 /**
91 * @return DatabaseConnection
92 */
93 protected function getDatabase() {
94 return $GLOBALS['TYPO3_DB'];
95 }
96 }