‪TYPO3CMS  ‪main
DatabaseLanguageRows.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 
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 
28 {
37  public function ‪addData(array $result)
38  {
39  if (!empty($result['processedTca']['ctrl']['languageField'])
40  && !empty($result['processedTca']['ctrl']['transOrigPointerField'])
41  ) {
42  $languageField = $result['processedTca']['ctrl']['languageField'];
43  $fieldWithUidOfDefaultRecord = $result['processedTca']['ctrl']['transOrigPointerField'];
44 
45  if (isset($result['databaseRow'][$languageField]) && $result['databaseRow'][$languageField] > 0
46  && isset($result['databaseRow'][$fieldWithUidOfDefaultRecord]) && $result['databaseRow'][$fieldWithUidOfDefaultRecord] > 0
47  ) {
48  // Default language record of localized record
49  $defaultLanguageRow = $this->‪getRecordWorkspaceOverlay(
50  $result['tableName'],
51  (int)$result['databaseRow'][$fieldWithUidOfDefaultRecord]
52  );
53  if (empty($defaultLanguageRow)) {
55  'Default language record with id ' . (int)$result['databaseRow'][$fieldWithUidOfDefaultRecord]
56  . ' not found in table ' . $result['tableName'] . ' while editing record ' . $result['databaseRow']['uid'],
57  1438249426
58  );
59  }
60  $result['defaultLanguageRow'] = $defaultLanguageRow;
61 
62  // Unserialize the "original diff source" if given
63  if (!empty($result['processedTca']['ctrl']['transOrigDiffSourceField'])
64  && !empty($result['databaseRow'][$result['processedTca']['ctrl']['transOrigDiffSourceField']])
65  ) {
66  $defaultLanguageKey = $result['tableName'] . ':' . (int)$result['databaseRow']['uid'];
67  $result['defaultLanguageDiffRow'][$defaultLanguageKey] = json_decode(
68  (string)$result['databaseRow'][$result['processedTca']['ctrl']['transOrigDiffSourceField']],
69  true
70  );
71  }
72 
73  // Add language overlays from further localizations if requested
74  // @todo: Permission check if user is in "restrict ot language" is missing here.
75  // @todo: The TranslationConfigurationProvider is more stupid than good for us ... invent a better translation overlay api!
76  if (!empty($result['userTsConfig']['options.']['additionalPreviewLanguages'])) {
77  $additionalLanguageUids = ‪GeneralUtility::intExplode(',', (string)$result['userTsConfig']['options.']['additionalPreviewLanguages'], true);
78  $translationProvider = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
79  foreach ($additionalLanguageUids as $additionalLanguageUid) {
80  // Continue if this system language record does not exist or if 0 or -1 is requested
81  // or if row is the same as the to-be-displayed row
82  if ($additionalLanguageUid <= 0
83  || !isset($result['systemLanguageRows'][$additionalLanguageUid])
84  || $additionalLanguageUid === (int)$result['databaseRow'][$languageField]
85  ) {
86  continue;
87  }
88  $translationInfo = $translationProvider->translationInfo(
89  $result['tableName'],
90  (int)$result['databaseRow'][$fieldWithUidOfDefaultRecord],
91  $additionalLanguageUid
92  );
93  if (!empty($translationInfo['translations'][$additionalLanguageUid]['uid'])) {
95  $result['tableName'],
96  (int)$translationInfo['translations'][$additionalLanguageUid]['uid']
97  );
98  $result['additionalLanguageRows'][$additionalLanguageUid] = ‪$record;
99  }
100  }
101  }
102 
103  // @todo do that only if l10n_parent > 0 (not in "free mode")?
104  if (!empty($result['processedTca']['ctrl']['translationSource'])
105  && is_string($result['processedTca']['ctrl']['translationSource'])
106  ) {
107  $translationSourceFieldName = $result['processedTca']['ctrl']['translationSource'];
108  if (isset($result['databaseRow'][$translationSourceFieldName])
109  && $result['databaseRow'][$translationSourceFieldName] > 0
110  ) {
111  $uidOfTranslationSource = $result['databaseRow'][$translationSourceFieldName];
112  $result['sourceLanguageRow'] = $this->‪getRecordWorkspaceOverlay(
113  $result['tableName'],
114  $uidOfTranslationSource
115  );
116  }
117  }
118  }
119  }
120 
121  return $result;
122  }
123 
127  protected function ‪getRecordWorkspaceOverlay(string $tableName, int ‪$uid): array
128  {
129  $row = BackendUtility::getRecordWSOL($tableName, ‪$uid);
130 
131  return $row ?: [];
132  }
133 }
‪TYPO3\CMS\Backend\Form\Exception\DatabaseDefaultLanguageException
Definition: DatabaseDefaultLanguageException.php:23
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseLanguageRows\getRecordWorkspaceOverlay
‪getRecordWorkspaceOverlay(string $tableName, int $uid)
Definition: DatabaseLanguageRows.php:127
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseLanguageRows\addData
‪array addData(array $result)
Definition: DatabaseLanguageRows.php:37
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
Definition: TranslationConfigurationProvider.php:39
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseLanguageRows
Definition: DatabaseLanguageRows.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\GeneralUtility\intExplode
‪static list< int > intExplode(string $delimiter, string $string, bool $removeEmptyValues=false)
Definition: GeneralUtility.php:756