‪TYPO3CMS  11.5
TranslationConfigurationProvider.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
29 
37 {
38  protected array ‪$systemLanguageCache = [];
39 
47  public function getSystemLanguages($pageId = 0)
48  {
49  if (isset($this->‪systemLanguageCache[$pageId])) {
50  return $this->‪systemLanguageCache[$pageId];
51  }
53  ‪$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
54  if ($pageId === 0) {
55  // Used for e.g. filelist, where there is no site selected
56  // This also means that there is no "-1" (All Languages) selectable.
57  $sites = ‪$siteFinder->getAllSites();
58  foreach ($sites as $site) {
61  $site->getAvailableLanguages($this->getBackendUserAuthentication()),
62  $site,
63  true
64  );
65  }
66  } else {
67  try {
68  $site = ‪$siteFinder->getSiteByPageId((int)$pageId);
69  } catch (SiteNotFoundException $e) {
70  $site = new NullSite();
71  }
72  $siteLanguages = $site->getAvailableLanguages($this->‪getBackendUserAuthentication(), true);
73  if (!isset($siteLanguages[0])) {
74  $siteLanguages[0] = $site->getDefaultLanguage();
75  }
78  $siteLanguages,
79  $site,
80  false
81  );
82  }
86  }
87 
88  protected function ‪addSiteLanguagesToConsolidatedList(array ‪$allSystemLanguages, array $languagesOfSpecificSite, ‪SiteInterface $site, bool $includeSiteSuffix): array
89  {
90  foreach ($languagesOfSpecificSite as $language) {
91  $languageId = $language->getLanguageId();
92  if (isset(‪$allSystemLanguages[$languageId])) {
93  // Language already provided by another site, just add the label separately
94  ‪$allSystemLanguages[$languageId]['title'] .= ', ' . $language->getTitle() . ' [Site: ' . $site->‪getIdentifier() . ']';
95  } else {
96  ‪$allSystemLanguages[$languageId] = [
97  'uid' => $languageId,
98  'title' => $language->getTitle() . ($includeSiteSuffix ? ' [Site: ' . $site->‪getIdentifier() . ']' : ''),
99  'ISOcode' => $language->getTwoLetterIsoCode(),
100  'flagIcon' => $language->getFlagIdentifier(),
101  ];
102  }
103  }
104  return ‪$allSystemLanguages;
105  }
106 
118  public function ‪translationInfo($table, $uid, $languageUid = 0, array $row = null, $selFieldList = '')
119  {
120  if (!‪$GLOBALS['TCA'][$table] || !$uid) {
121  return 'No table "' . $table . '" or no UID value';
122  }
123  if ($row === null) {
124  $row = BackendUtility::getRecordWSOL($table, $uid);
125  }
126  if (!is_array($row)) {
127  return 'Record "' . $table . '_' . $uid . '" was not found';
128  }
129  if (!BackendUtility::isTableLocalizable($table)) {
130  return 'Translation is not supported for this table!';
131  }
132  if ($row[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0) {
133  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']] . '")';
134  }
135  if ($row[‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0) {
136  return 'Record "' . $table . '_' . $uid . '" seems to be a translation already (has a relation to record "' . $row[‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] . '")';
137  }
138  // Look for translations of this record, index by language field value:
139  if (!empty($selFieldList)) {
140  if (is_array($selFieldList)) {
141  $selectFields = $selFieldList;
142  } else {
143  $selectFields = ‪GeneralUtility::trimExplode(',', $selFieldList);
144  }
145  } else {
146  $selectFields = ['uid', ‪$GLOBALS['TCA'][$table]['ctrl']['languageField']];
147  }
148  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
149  $queryBuilder->getRestrictions()
150  ->removeAll()
151  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
152  ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->‪getBackendUserAuthentication()->workspace));
153  $queryBuilder
154  ->select(...$selectFields)
155  ->from($table)
156  ->where(
157  $queryBuilder->expr()->eq(
158  ‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'],
159  $queryBuilder->createNamedParameter($uid, ‪Connection::PARAM_INT)
160  ),
161  $queryBuilder->expr()->eq(
162  'pid',
163  $queryBuilder->createNamedParameter(
164  $row['pid'],
166  )
167  )
168  );
169  if (!$languageUid) {
170  $queryBuilder->andWhere(
171  $queryBuilder->expr()->gt(
172  ‪$GLOBALS['TCA'][$table]['ctrl']['languageField'],
173  $queryBuilder->createNamedParameter(0, ‪Connection::PARAM_INT)
174  )
175  );
176  } else {
177  $queryBuilder
178  ->andWhere(
179  $queryBuilder->expr()->eq(
180  ‪$GLOBALS['TCA'][$table]['ctrl']['languageField'],
181  $queryBuilder->createNamedParameter($languageUid, ‪Connection::PARAM_INT)
182  )
183  );
184  }
185  $translationRecords = $queryBuilder
186  ->executeQuery()
187  ->fetchAllAssociative();
188 
189  $translations = [];
190  $translationsErrors = [];
191  foreach ($translationRecords as $translationRecord) {
192  if (!isset($translations[$translationRecord[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']]])) {
193  $translations[$translationRecord[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']]] = $translationRecord;
194  } else {
195  $translationsErrors[$translationRecord[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']]][] = $translationRecord;
196  }
197  }
198  return [
199  'table' => $table,
200  'uid' => $uid,
201  'CType' => $row['CType'] ?? '',
202  'sys_language_uid' => $row[‪$GLOBALS['TCA'][$table]['ctrl']['languageField'] ?? null] ?? null,
203  'translations' => $translations,
204  'excessive_translations' => $translationsErrors,
205  ];
206  }
207 
209  {
210  return ‪$GLOBALS['BE_USER'];
211  }
212 }
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪TYPO3\CMS\Core\Site\Entity\SiteInterface
Definition: SiteInterface.php:26
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\$siteFinder
‪$siteFinder
Definition: TranslationConfigurationProvider.php:53
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:49
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\translationInfo
‪mixed translationInfo($table, $uid, $languageUid=0, array $row=null, $selFieldList='')
Definition: TranslationConfigurationProvider.php:118
‪TYPO3\CMS\Core\Site\Entity\NullSite
Definition: NullSite.php:32
‪TYPO3\CMS\Core\Exception\SiteNotFoundException
Definition: SiteNotFoundException.php:25
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\getBackendUserAuthentication
‪getBackendUserAuthentication()
Definition: TranslationConfigurationProvider.php:208
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\addSiteLanguagesToConsolidatedList
‪addSiteLanguagesToConsolidatedList(array $allSystemLanguages, array $languagesOfSpecificSite, SiteInterface $site, bool $includeSiteSuffix)
Definition: TranslationConfigurationProvider.php:88
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\$allSystemLanguages
‪return $allSystemLanguages
Definition: TranslationConfigurationProvider.php:85
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Site\Entity\SiteInterface\getIdentifier
‪string getIdentifier()
‪TYPO3\CMS\Backend\Configuration
Definition: BackendUserConfiguration.php:18
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\systemLanguageCache
‪array< LanguageRef, function getSystemLanguages( $pageId=0) { if(isset( $this->systemLanguageCache[ $pageId])) { return $this-> systemLanguageCache[$pageId]
Definition: TranslationConfigurationProvider.php:50
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\$allSystemLanguages
‪$allSystemLanguages
Definition: TranslationConfigurationProvider.php:52
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:38
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
Definition: TranslationConfigurationProvider.php:37
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\$systemLanguageCache
‪array $systemLanguageCache
Definition: TranslationConfigurationProvider.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction
Definition: WorkspaceRestriction.php:40