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