‪TYPO3CMS  10.4
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 
28 
35 {
39  protected ‪$systemLanguageCache = [];
40 
48  public function ‪getSystemLanguages($pageId = 0)
49  {
50  if (isset($this->systemLanguageCache[$pageId])) {
51  return $this->systemLanguageCache[$pageId];
52  }
53  $allSystemLanguages = [];
54  $siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
55  if ($pageId === 0) {
56  // Used for e.g. filelist, where there is no site selected
57  // This also means that there is no "-1" (All Languages) selectable.
58  $sites = $siteFinder->getAllSites();
59  foreach ($sites as $site) {
60  $allSystemLanguages = $this->‪addSiteLanguagesToConsolidatedList(
61  $allSystemLanguages,
62  $site->getAvailableLanguages($this->getBackendUserAuthentication()),
63  $site,
64  true
65  );
66  }
67  } else {
68  try {
69  $site = $siteFinder->getSiteByPageId((int)$pageId);
70  } catch (‪SiteNotFoundException $e) {
71  $site = new ‪NullSite();
72  }
73  $siteLanguages = $site->getAvailableLanguages($this->‪getBackendUserAuthentication(), true);
74  if (!isset($siteLanguages[0])) {
75  $siteLanguages[0] = $site->getDefaultLanguage();
76  }
77  $allSystemLanguages = $this->‪addSiteLanguagesToConsolidatedList(
78  $allSystemLanguages,
79  $siteLanguages,
80  $site,
81  false
82  );
83  }
84  ksort($allSystemLanguages);
85  $this->systemLanguageCache[$pageId] = $allSystemLanguages;
86  return $allSystemLanguages;
87  }
88 
89  protected function ‪addSiteLanguagesToConsolidatedList(array $allSystemLanguages, array $languagesOfSpecificSite, ‪SiteInterface $site, bool $includeSiteSuffix): array
90  {
91  foreach ($languagesOfSpecificSite as $language) {
92  $languageId = $language->getLanguageId();
93  if (isset($allSystemLanguages[$languageId])) {
94  // Language already provided by another site, just add the label separately
95  $allSystemLanguages[$languageId]['title'] .= ', ' . $language->getTitle() . ' [Site: ' . $site->‪getIdentifier() . ']';
96  } else {
97  $allSystemLanguages[$languageId] = [
98  'uid' => $languageId,
99  'title' => $language->getTitle() . ($includeSiteSuffix ? ' [Site: ' . $site->‪getIdentifier() . ']' : ''),
100  'ISOcode' => $language->getTwoLetterIsoCode(),
101  'flagIcon' => $language->getFlagIdentifier(),
102  ];
103  }
104  }
105  return $allSystemLanguages;
106  }
107 
119  public function ‪translationInfo($table, $uid, $languageUid = 0, array $row = null, $selFieldList = '')
120  {
121  if (!‪$GLOBALS['TCA'][$table] || !$uid) {
122  return 'No table "' . $table . '" or no UID value';
123  }
124  if ($row === null) {
125  $row = ‪BackendUtility::getRecordWSOL($table, $uid);
126  }
127  if (!is_array($row)) {
128  return 'Record "' . $table . '_' . $uid . '" was not found';
129  }
131  return 'Translation is not supported for this table!';
132  }
133  if ($row[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0) {
134  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']] . '")';
135  }
136  if ($row[‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0) {
137  return 'Record "' . $table . '_' . $uid . '" seems to be a translation already (has a relation to record "' . $row[‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] . '")';
138  }
139  // Look for translations of this record, index by language field value:
140  if (!$selFieldList) {
141  $selFieldList = 'uid,' . ‪$GLOBALS['TCA'][$table]['ctrl']['languageField'];
142  }
143  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
144  $queryBuilder->getRestrictions()
145  ->removeAll()
146  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
147  ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->‪getBackendUserAuthentication()->workspace));
148  $queryBuilder
149  ->select(...‪GeneralUtility::trimExplode(',', $selFieldList))
150  ->from($table)
151  ->where(
152  $queryBuilder->expr()->eq(
153  ‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'],
154  $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
155  ),
156  $queryBuilder->expr()->eq(
157  'pid',
158  $queryBuilder->createNamedParameter(
159  $row['pid'],
160  \PDO::PARAM_INT
161  )
162  )
163  );
164  if (!$languageUid) {
165  $queryBuilder->andWhere(
166  $queryBuilder->expr()->gt(
167  ‪$GLOBALS['TCA'][$table]['ctrl']['languageField'],
168  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
169  )
170  );
171  } else {
172  $queryBuilder
173  ->andWhere(
174  $queryBuilder->expr()->eq(
175  ‪$GLOBALS['TCA'][$table]['ctrl']['languageField'],
176  $queryBuilder->createNamedParameter($languageUid, \PDO::PARAM_INT)
177  )
178  );
179  }
180  $translationRecords = $queryBuilder
181  ->execute()
182  ->fetchAll();
183 
184  $translations = [];
185  $translationsErrors = [];
186  foreach ($translationRecords as $translationRecord) {
187  if (!isset($translations[$translationRecord[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']]])) {
188  $translations[$translationRecord[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']]] = $translationRecord;
189  } else {
190  $translationsErrors[$translationRecord[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']]][] = $translationRecord;
191  }
192  }
193  return [
194  'table' => $table,
195  'uid' => $uid,
196  'CType' => $row['CType'],
197  'sys_language_uid' => $row[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']],
198  'translations' => $translations,
199  'excessive_translations' => $translationsErrors
200  ];
201  }
202 
204  {
205  return ‪$GLOBALS['BE_USER'];
206  }
207 }
‪TYPO3\CMS\Core\Site\Entity\SiteInterface
Definition: SiteInterface.php:26
‪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:26
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\getBackendUserAuthentication
‪getBackendUserAuthentication()
Definition: TranslationConfigurationProvider.php:202
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\addSiteLanguagesToConsolidatedList
‪addSiteLanguagesToConsolidatedList(array $allSystemLanguages, array $languagesOfSpecificSite, SiteInterface $site, bool $includeSiteSuffix)
Definition: TranslationConfigurationProvider.php:88
‪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\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:139
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
Definition: TranslationConfigurationProvider.php:35
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\getSystemLanguages
‪array getSystemLanguages($pageId=0)
Definition: TranslationConfigurationProvider.php:47
‪TYPO3\CMS\Backend\Utility\BackendUtility\isTableLocalizable
‪static bool isTableLocalizable($table)
Definition: BackendUtility.php:578
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪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:46
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction
Definition: WorkspaceRestriction.php:39