TYPO3 CMS  TYPO3_8-7
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 (!empty($result['databaseRow'][$languageField]) && !empty($result['databaseRow'][$fieldWithUidOfDefaultRecord])) {
46  // Table pages has its overlays in pages_language_overlay, this is accounted here
47  $tableNameWithDefaultRecords = $result['tableName'];
48  if ($tableNameWithDefaultRecords === 'pages_language_overlay') {
49  $tableNameWithDefaultRecords = 'pages';
50  }
51 
52  // Default language record of localized record
53  $parentUid = is_array($result['databaseRow'][$fieldWithUidOfDefaultRecord])
54  ? (int)$result['databaseRow'][$fieldWithUidOfDefaultRecord][0]['uid']
55  : (int)$result['databaseRow'][$fieldWithUidOfDefaultRecord];
56  $defaultLanguageRow = $this->getRecordWorkspaceOverlay(
57  $tableNameWithDefaultRecords,
58  $parentUid
59  );
60  if (empty($defaultLanguageRow)) {
62  'Default language record with id ' . $parentUid
63  . ' not found in table ' . $result['tableName'] . ' while editing record ' . $result['databaseRow']['uid'],
64  1438249426
65  );
66  }
67  $result['defaultLanguageRow'] = $defaultLanguageRow;
68 
69  // Unserialize the "original diff source" if given
70  if (!empty($result['processedTca']['ctrl']['transOrigDiffSourceField'])
71  && !empty($result['databaseRow'][$result['processedTca']['ctrl']['transOrigDiffSourceField']])
72  ) {
73  $defaultLanguageKey = $result['tableName'] . ':' . (int)$result['databaseRow']['uid'];
74  $result['defaultLanguageDiffRow'][$defaultLanguageKey] = unserialize(
75  $result['databaseRow'][$result['processedTca']['ctrl']['transOrigDiffSourceField']],
76  ['allowed_classes' => false]
77  );
78  }
79 
80  // Add language overlays from further localizations if requested
81  // @todo: Permission check if user is in "restrict ot language" is missing here.
82  // @todo: The TranslationConfigurationProvider is more stupid than good for us ... invent a better translation overlay api!
83  if (!empty($result['userTsConfig']['options.']['additionalPreviewLanguages'])) {
84  $additionalLanguageUids = GeneralUtility::intExplode(',', $result['userTsConfig']['options.']['additionalPreviewLanguages'], true);
86  $translationProvider = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
87  foreach ($additionalLanguageUids as $additionalLanguageUid) {
88  // Continue if this system language record does not exist or if 0 or -1 is requested
89  // or if row is the same as the to-be-displayed row
90  if ($additionalLanguageUid <= 0
91  || !isset($result['systemLanguageRows'][$additionalLanguageUid])
92  || $additionalLanguageUid === (int)$result['databaseRow'][$languageField]
93  ) {
94  continue;
95  }
96  $translationInfo = $translationProvider->translationInfo(
97  $tableNameWithDefaultRecords,
98  (int)$result['databaseRow'][$fieldWithUidOfDefaultRecord],
99  $additionalLanguageUid
100  );
101  if (!empty($translationInfo['translations'][$additionalLanguageUid]['uid'])) {
102  $record = $this->getRecordWorkspaceOverlay(
103  $result['tableName'],
104  (int)$translationInfo['translations'][$additionalLanguageUid]['uid']
105  );
106  $result['additionalLanguageRows'][$additionalLanguageUid] = $record;
107  }
108  }
109  }
110 
111  // @todo do that only if l10n_parent > 0 (not in "free mode")?
112  if (!empty($result['processedTca']['ctrl']['translationSource'])
113  && is_string($result['processedTca']['ctrl']['translationSource'])
114  ) {
115  $translationSourceFieldName = $result['processedTca']['ctrl']['translationSource'];
116  if (isset($result['databaseRow'][$translationSourceFieldName])
117  && $result['databaseRow'][$translationSourceFieldName] > 0
118  ) {
119  $uidOfTranslationSource = $result['databaseRow'][$translationSourceFieldName];
120  $result['sourceLanguageRow'] = $this->getRecordWorkspaceOverlay(
121  $result['tableName'],
122  $uidOfTranslationSource
123  );
124  }
125  }
126  }
127  }
128 
129  return $result;
130  }
131 
139  protected function getRecordWorkspaceOverlay(string $tableName, int $uid): array
140  {
141  $row = BackendUtility::getRecordWSOL($tableName, $uid);
142 
143  return $row ?: [];
144  }
145 }
static getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
static intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)