TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
TranslationConfigurationProvider.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Configuration;
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 
24 
29 {
33  protected function getLanguageService()
34  {
35  return $GLOBALS['LANG'];
36  }
37 
45  public function getSystemLanguages($pageId = 0)
46  {
47  $modSharedTSconfig = BackendUtility::getModTSconfig($pageId, 'mod.SHARED');
48 
49  // default language and "all languages" are always present
50  $languages = [
51  // 0: default language
52  0 => [
53  'uid' => 0,
54  'title' => $this->getDefaultLanguageLabel($modSharedTSconfig),
55  'ISOcode' => 'DEF',
56  'flagIcon' => $this->getDefaultLanguageFlag($modSharedTSconfig),
57  ],
58  // -1: all languages
59  -1 => [
60  'uid' => -1,
61  'title' => $this->getLanguageService()->getLL('multipleLanguages'),
62  'ISOcode' => 'DEF',
63  'flagIcon' => 'flags-multiple',
64  ],
65  ];
66 
67  // add the additional languages from database records
68  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
69  $languageRecords = $queryBuilder
70  ->select('*')
71  ->from('sys_language')
72  ->orderBy('sorting')
73  ->execute()
74  ->fetchAll();
75  foreach ($languageRecords as $languageRecord) {
76  $languages[$languageRecord['uid']] = $languageRecord;
77  // @todo: this should probably resolve language_isocode too and throw a deprecation if not filled
78  if ($languageRecord['static_lang_isocode'] && ExtensionManagementUtility::isLoaded('static_info_tables')) {
79  $staticLangRow = BackendUtility::getRecord('static_languages', $languageRecord['static_lang_isocode'], 'lg_iso_2');
80  if ($staticLangRow['lg_iso_2']) {
81  $languages[$languageRecord['uid']]['ISOcode'] = $staticLangRow['lg_iso_2'];
82  }
83  }
84  if ($languageRecord['flag'] !== '') {
85  $languages[$languageRecord['uid']]['flagIcon'] = 'flags-' . $languageRecord['flag'];
86  }
87  }
88  return $languages;
89  }
90 
102  public function translationInfo($table, $uid, $languageUid = 0, array $row = null, $selFieldList = '')
103  {
104  if (!$GLOBALS['TCA'][$table] || !$uid) {
105  return 'No table "' . $table . '" or no UID value';
106  }
107  if ($row === null) {
108  $row = BackendUtility::getRecordWSOL($table, $uid);
109  }
110  if (!is_array($row)) {
111  return 'Record "' . $table . '_' . $uid . '" was not found';
112  }
113  $translationTable = $this->getTranslationTable($table);
114  if ($translationTable === '') {
115  return 'Translation is not supported for this table!';
116  }
117  if ($translationTable === $table && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0) {
118  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']] . '")';
119  }
120  if ($translationTable === $table && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0) {
121  return 'Record "' . $table . '_' . $uid . '" seems to be a translation already (has a relation to record "' . $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] . '")';
122  }
123  // Look for translations of this record, index by language field value:
124  if (!$selFieldList) {
125  $selFieldList = 'uid,' . $GLOBALS['TCA'][$translationTable]['ctrl']['languageField'];
126  }
127  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($translationTable);
128  $queryBuilder->getRestrictions()
129  ->removeAll()
130  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
131  ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
132  $queryBuilder
133  ->select(...GeneralUtility::trimExplode(',', $selFieldList))
134  ->from($translationTable)
135  ->where(
136  $queryBuilder->expr()->eq(
137  $GLOBALS['TCA'][$translationTable]['ctrl']['transOrigPointerField'],
138  $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
139  ),
140  $queryBuilder->expr()->eq(
141  'pid',
142  $queryBuilder->createNamedParameter(
143  ($table === 'pages' ? $row['uid'] : $row['pid']),
144  \PDO::PARAM_INT
145  )
146  )
147  );
148  if (!$languageUid) {
149  $queryBuilder->andWhere(
150  $queryBuilder->expr()->gt(
151  $GLOBALS['TCA'][$translationTable]['ctrl']['languageField'],
152  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
153  )
154  );
155  } else {
156  $queryBuilder
157  ->andWhere(
158  $queryBuilder->expr()->eq(
159  $GLOBALS['TCA'][$translationTable]['ctrl']['languageField'],
160  $queryBuilder->createNamedParameter($languageUid, \PDO::PARAM_INT)
161  )
162  );
163  }
164  $translationRecords = $queryBuilder
165  ->execute()
166  ->fetchAll();
167 
168  $translations = [];
169  $translationsErrors = [];
170  foreach ($translationRecords as $translationRecord) {
171  if (!isset($translations[$translationRecord[$GLOBALS['TCA'][$translationTable]['ctrl']['languageField']]])) {
172  $translations[$translationRecord[$GLOBALS['TCA'][$translationTable]['ctrl']['languageField']]] = $translationRecord;
173  } else {
174  $translationsErrors[$translationRecord[$GLOBALS['TCA'][$translationTable]['ctrl']['languageField']]][] = $translationRecord;
175  }
176  }
177  return [
178  'table' => $table,
179  'uid' => $uid,
180  'CType' => $row['CType'],
181  'sys_language_uid' => $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']],
182  'translation_table' => $translationTable,
183  'translations' => $translations,
184  'excessive_translations' => $translationsErrors
185  ];
186  }
187 
194  public function getTranslationTable($table)
195  {
196  return $this->isTranslationInOwnTable($table) ? $table : $this->foreignTranslationTable($table);
197  }
198 
205  public function isTranslationInOwnTable($table)
206  {
207  return $GLOBALS['TCA'][$table]['ctrl']['languageField'] && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] && $table !== 'pages_language_overlay';
208  }
209 
216  public function foreignTranslationTable($table)
217  {
218  return $table === 'pages' ? 'pages_language_overlay' : '';
219  }
220 
225  protected function getDefaultLanguageFlag(array $modSharedTSconfig)
226  {
227  if (strlen($modSharedTSconfig['properties']['defaultLanguageFlag'])) {
228  $defaultLanguageFlag = 'flags-' . $modSharedTSconfig['properties']['defaultLanguageFlag'];
229  } else {
230  $defaultLanguageFlag = 'empty-empty';
231  }
232  return $defaultLanguageFlag;
233  }
234 
239  protected function getDefaultLanguageLabel(array $modSharedTSconfig)
240  {
241  if (strlen($modSharedTSconfig['properties']['defaultLanguageLabel'])) {
242  $defaultLanguageLabel = $modSharedTSconfig['properties']['defaultLanguageLabel'] . ' (' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage') . ')';
243  } else {
244  $defaultLanguageLabel = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage');
245  }
246  return $defaultLanguageLabel;
247  }
248 }
static getRecordWSOL($table, $uid, $fields= '*', $where= '', $useDeleteClause=true, $unsetMovePointers=false)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static getRecord($table, $uid, $fields= '*', $where= '', $useDeleteClause=true)
translationInfo($table, $uid, $languageUid=0, array $row=null, $selFieldList= '')
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)