‪TYPO3CMS  9.5
TranslationConfigurationProvider.php
Go to the documentation of this file.
1 <?php
2 
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
28 
35 {
39  protected function ‪getLanguageService()
40  {
41  return ‪$GLOBALS['LANG'];
42  }
43 
51  public function ‪getSystemLanguages($pageId = 0)
52  {
53  try {
54  $site = GeneralUtility::makeInstance(SiteMatcher::class)->matchByPageId((int)$pageId);
55  $siteLanguages = $site->getAvailableLanguages($this->‪getBackendUserAuthentication(), true);
56 
57  if (!isset($siteLanguages[0])) {
58  $siteLanguages[0] = $site->getDefaultLanguage();
59  ksort($siteLanguages);
60  }
61 
62  $languages = [];
63  foreach ($siteLanguages as $id => $siteLanguage) {
64  $languages[$id] = [
65  'uid' => $id,
66  'title' => $siteLanguage->getTitle(),
67  'ISOcode' => $siteLanguage->getTwoLetterIsoCode(),
68  'flagIcon' => $siteLanguage->getFlagIdentifier(),
69  ];
70  }
71  } catch (‪SiteNotFoundException $e) {
72  // default language and "all languages" are always present
73  $modSharedTSconfig = ‪BackendUtility::getPagesTSconfig($pageId)['mod.']['SHARED.'] ?? [];
74  $languages = [
75  // 0: default language
76  0 => [
77  'uid' => 0,
78  'title' => $this->‪getDefaultLanguageLabel($modSharedTSconfig),
79  'ISOcode' => 'DEF',
80  'flagIcon' => $this->‪getDefaultLanguageFlag($modSharedTSconfig),
81  ],
82  // -1: all languages
83  -1 => [
84  'uid' => -1,
85  'title' => $this->‪getLanguageService()->‪getLL('multipleLanguages'),
86  'ISOcode' => 'DEF',
87  'flagIcon' => 'flags-multiple',
88  ],
89  ];
90 
91  // add the additional languages from database records
92  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
93  $languageRecords = $queryBuilder
94  ->select('*')
95  ->from('sys_language')
96  ->orderBy('sorting')
97  ->execute()
98  ->fetchAll();
99  foreach ($languageRecords as $languageRecord) {
100  $languages[$languageRecord['uid']] = $languageRecord;
101  // @todo: this should probably resolve language_isocode too and throw a deprecation if not filled
102  if ($languageRecord['static_lang_isocode'] && ‪ExtensionManagementUtility::isLoaded('static_info_tables')) {
103  $staticLangRow = ‪BackendUtility::getRecord('static_languages', $languageRecord['static_lang_isocode'], 'lg_iso_2');
104  if ($staticLangRow['lg_iso_2']) {
105  $languages[$languageRecord['uid']]['ISOcode'] = $staticLangRow['lg_iso_2'];
106  }
107  }
108  if ($languageRecord['flag'] !== '') {
109  $languages[$languageRecord['uid']]['flagIcon'] = 'flags-' . $languageRecord['flag'];
110  }
111  }
112  }
113 
114  return $languages;
115  }
116 
128  public function ‪translationInfo($table, $uid, $languageUid = 0, array $row = null, $selFieldList = '')
129  {
130  if (!‪$GLOBALS['TCA'][$table] || !$uid) {
131  return 'No table "' . $table . '" or no UID value';
132  }
133  if ($row === null) {
134  $row = ‪BackendUtility::getRecordWSOL($table, $uid);
135  }
136  if (!is_array($row)) {
137  return 'Record "' . $table . '_' . $uid . '" was not found';
138  }
140  return 'Translation is not supported for this table!';
141  }
142  if ($row[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0) {
143  return 'Record "' . $table . '_' . $uid . '" seems to be a translation already (has a language value "' . $row[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']] . '", relation to record "' . $row[‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] . '")';
144  }
145  if ($row[‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0) {
146  return 'Record "' . $table . '_' . $uid . '" seems to be a translation already (has a relation to record "' . $row[‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] . '")';
147  }
148  // Look for translations of this record, index by language field value:
149  if (!$selFieldList) {
150  $selFieldList = 'uid,' . ‪$GLOBALS['TCA'][$table]['ctrl']['languageField'];
151  }
152  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
153  $queryBuilder->getRestrictions()
154  ->removeAll()
155  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
156  ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
157  $queryBuilder
158  ->select(...GeneralUtility::trimExplode(',', $selFieldList))
159  ->from($table)
160  ->where(
161  $queryBuilder->expr()->eq(
162  ‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'],
163  $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
164  ),
165  $queryBuilder->expr()->eq(
166  'pid',
167  $queryBuilder->createNamedParameter(
168  $row['pid'],
169  \PDO::PARAM_INT
170  )
171  )
172  );
173  if (!$languageUid) {
174  $queryBuilder->andWhere(
175  $queryBuilder->expr()->gt(
176  ‪$GLOBALS['TCA'][$table]['ctrl']['languageField'],
177  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
178  )
179  );
180  } else {
181  $queryBuilder
182  ->andWhere(
183  $queryBuilder->expr()->eq(
184  ‪$GLOBALS['TCA'][$table]['ctrl']['languageField'],
185  $queryBuilder->createNamedParameter($languageUid, \PDO::PARAM_INT)
186  )
187  );
188  }
189  $translationRecords = $queryBuilder
190  ->execute()
191  ->fetchAll();
192 
193  $translations = [];
194  $translationsErrors = [];
195  foreach ($translationRecords as $translationRecord) {
196  if (!isset($translations[$translationRecord[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']]])) {
197  $translations[$translationRecord[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']]] = $translationRecord;
198  } else {
199  $translationsErrors[$translationRecord[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']]][] = $translationRecord;
200  }
201  }
202  return [
203  'table' => $table,
204  'uid' => $uid,
205  'CType' => $row['CType'],
206  'sys_language_uid' => $row[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']],
207  'translations' => $translations,
208  'excessive_translations' => $translationsErrors
209  ];
210  }
211 
219  public function ‪getTranslationTable($table)
220  {
221  trigger_error('TranslationConfigurationProvider->getTranslationTable() will be removed in TYPO3 v10.0, as the translation table is always the same as the original table.', E_USER_DEPRECATED);
222  return ‪BackendUtility::isTableLocalizable($table) ? $table : '';
223  }
224 
232  public function ‪isTranslationInOwnTable($table)
233  {
234  trigger_error('TranslationConfigurationProvider->isTranslationInOwnTable() will be removed in TYPO3 v10.0, as the translation table is always the same as the original table.', E_USER_DEPRECATED);
235  return ‪$GLOBALS['TCA'][$table]['ctrl']['languageField'] && ‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
236  }
237 
247  public function ‪foreignTranslationTable($table)
248  {
249  trigger_error('TranslationConfigurationProvider->foreignTranslationTable() will be removed in TYPO3 v10.0, as the translation table is always the same as the original table.', E_USER_DEPRECATED);
250  return '';
251  }
252 
257  protected function ‪getDefaultLanguageFlag(array $modSharedTSconfig)
258  {
259  if (strlen($modSharedTSconfig['defaultLanguageFlag'])) {
260  $defaultLanguageFlag = 'flags-' . $modSharedTSconfig['defaultLanguageFlag'];
261  } else {
262  $defaultLanguageFlag = 'empty-empty';
263  }
264  return $defaultLanguageFlag;
265  }
266 
271  protected function ‪getDefaultLanguageLabel(array $modSharedTSconfig)
272  {
273  if (strlen($modSharedTSconfig['defaultLanguageLabel'])) {
274  $defaultLanguageLabel = $modSharedTSconfig['defaultLanguageLabel'] . ' (' . $this->‪getLanguageService()->‪sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage') . ')';
275  } else {
276  $defaultLanguageLabel = $this->‪getLanguageService()->‪sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage');
277  }
278  return $defaultLanguageLabel;
279  }
280 
282  {
283  return ‪$GLOBALS['BE_USER'];
284  }
285 }
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\getTranslationTable
‪string getTranslationTable($table)
Definition: TranslationConfigurationProvider.php:219
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\getDefaultLanguageFlag
‪string getDefaultLanguageFlag(array $modSharedTSconfig)
Definition: TranslationConfigurationProvider.php:257
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\isTranslationInOwnTable
‪bool isTranslationInOwnTable($table)
Definition: TranslationConfigurationProvider.php:232
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\foreignTranslationTable
‪string foreignTranslationTable($table)
Definition: TranslationConfigurationProvider.php:247
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\translationInfo
‪mixed translationInfo($table, $uid, $languageUid=0, array $row=null, $selFieldList='')
Definition: TranslationConfigurationProvider.php:128
‪TYPO3\CMS\Core\Exception\SiteNotFoundException
Definition: SiteNotFoundException.php:25
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction
Definition: BackendWorkspaceRestriction.php:28
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\getBackendUserAuthentication
‪getBackendUserAuthentication()
Definition: TranslationConfigurationProvider.php:281
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:158
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:36
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key, $exitOnError=null)
Definition: ExtensionManagementUtility.php:115
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\Configuration
Definition: BackendUserConfiguration.php:3
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\getLanguageService
‪LanguageService getLanguageService()
Definition: TranslationConfigurationProvider.php:39
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:174
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\getDefaultLanguageLabel
‪string getDefaultLanguageLabel(array $modSharedTSconfig)
Definition: TranslationConfigurationProvider.php:271
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:130
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
Definition: TranslationConfigurationProvider.php:35
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\getSystemLanguages
‪array getSystemLanguages($pageId=0)
Definition: TranslationConfigurationProvider.php:51
‪TYPO3\CMS\Backend\Utility\BackendUtility\isTableLocalizable
‪static bool isTableLocalizable($table)
Definition: BackendUtility.php:616
‪TYPO3\CMS\Backend\Utility\BackendUtility\getPagesTSconfig
‪static array getPagesTSconfig($id, $rootLine=null, $returnPartArray=false)
Definition: BackendUtility.php:864
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:26
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Localization\LanguageService\getLL
‪string getLL($index)
Definition: LanguageService.php:118
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Routing\SiteMatcher
Definition: SiteMatcher.php:53