‪TYPO3CMS  9.5
DatabaseLanguageRows.php
Go to the documentation of this file.
1 <?php
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 
22 
27 {
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] = unserialize(
68  $result['databaseRow'][$result['processedTca']['ctrl']['transOrigDiffSourceField']],
69  ['allowed_classes' => false]
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(',', $result['userTsConfig']['options.']['additionalPreviewLanguages'], true);
79  $translationProvider = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
80  foreach ($additionalLanguageUids as $additionalLanguageUid) {
81  // Continue if this system language record does not exist or if 0 or -1 is requested
82  // or if row is the same as the to-be-displayed row
83  if ($additionalLanguageUid <= 0
84  || !isset($result['systemLanguageRows'][$additionalLanguageUid])
85  || $additionalLanguageUid === (int)$result['databaseRow'][$languageField]
86  ) {
87  continue;
88  }
89  $translationInfo = $translationProvider->translationInfo(
90  $result['tableName'],
91  (int)$result['databaseRow'][$fieldWithUidOfDefaultRecord],
92  $additionalLanguageUid
93  );
94  if (!empty($translationInfo['translations'][$additionalLanguageUid]['uid'])) {
95  $record = $this->‪getRecordWorkspaceOverlay(
96  $result['tableName'],
97  (int)$translationInfo['translations'][$additionalLanguageUid]['uid']
98  );
99  $result['additionalLanguageRows'][$additionalLanguageUid] = $record;
100  }
101  }
102  }
103 
104  // @todo do that only if l10n_parent > 0 (not in "free mode")?
105  if (!empty($result['processedTca']['ctrl']['translationSource'])
106  && is_string($result['processedTca']['ctrl']['translationSource'])
107  ) {
108  $translationSourceFieldName = $result['processedTca']['ctrl']['translationSource'];
109  if (isset($result['databaseRow'][$translationSourceFieldName])
110  && $result['databaseRow'][$translationSourceFieldName] > 0
111  ) {
112  $uidOfTranslationSource = $result['databaseRow'][$translationSourceFieldName];
113  $result['sourceLanguageRow'] = $this->‪getRecordWorkspaceOverlay(
114  $result['tableName'],
115  $uidOfTranslationSource
116  );
117  }
118  }
119  }
120  }
121 
122  return $result;
123  }
124 
132  protected function ‪getRecordWorkspaceOverlay(string $tableName, int $uid): array
133  {
134  $row = ‪BackendUtility::getRecordWSOL($tableName, $uid);
135 
136  return $row ?: [];
137  }
138 }
‪TYPO3\CMS\Backend\Form\Exception\DatabaseDefaultLanguageException
Definition: DatabaseDefaultLanguageException.php:23
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseLanguageRows\getRecordWorkspaceOverlay
‪array getRecordWorkspaceOverlay(string $tableName, int $uid)
Definition: DatabaseLanguageRows.php:132
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseLanguageRows\addData
‪array addData(array $result)
Definition: DatabaseLanguageRows.php:37
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:2
‪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\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:22
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
Definition: TranslationConfigurationProvider.php:35
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseLanguageRows
Definition: DatabaseLanguageRows.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45