TYPO3  7.6
DatabaseLanguageRows.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Form\FormDataProvider;
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 
21 use TYPO3\CMS\Backend\Form\Exception\DatabaseDefaultLanguageException;
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  // Table pages has its overlays in pages_language_overlay, this is accounted here
49  $tableNameWithDefaultRecords = $result['tableName'];
50  if (!empty($result['processedTca']['ctrl']['transOrigPointerTable'])) {
51  $tableNameWithDefaultRecords = $result['processedTca']['ctrl']['transOrigPointerTable'];
52  }
53 
54  // Default language record of localized record
55  $defaultLanguageRow = BackendUtility::getRecordWSOL(
56  $tableNameWithDefaultRecords,
57  (int)$result['databaseRow'][$fieldWithUidOfDefaultRecord]
58  );
59  if (!is_array($defaultLanguageRow)) {
61  'Default language record with id ' . (int)$result['databaseRow'][$fieldWithUidOfDefaultRecord]
62  . ' not found in table ' . $result['tableName'] . ' while editing record ' . $result['databaseRow']['uid'],
63  1438249426
64  );
65  }
66  $result['defaultLanguageRow'] = $defaultLanguageRow;
67 
68  // Unserialize the "original diff source" if given
69  if (!empty($result['processedTca']['ctrl']['transOrigDiffSourceField'])
70  && !empty($result['databaseRow'][$result['processedTca']['ctrl']['transOrigDiffSourceField']])
71  ) {
72  $result['defaultLanguageDiffRow'] = unserialize($result['databaseRow'][$result['processedTca']['ctrl']['transOrigDiffSourceField']]);
73  }
74 
75  // Add language overlays from further localizations if requested
76  // @todo: Permission check if user is in "restrict ot language" is missing here.
77  // @todo: The TranslationConfigurationProvider is more stupid than good for us ... invent a better translation overlay api!
78  if (!empty($result['userTsConfig']['options.']['additionalPreviewLanguages'])) {
79  $additionalLanguageUids = GeneralUtility::intExplode(',', $result['userTsConfig']['options.']['additionalPreviewLanguages'], true);
81  $translationProvider = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
82  foreach ($additionalLanguageUids as $additionalLanguageUid) {
83  // Continue if this system language record does not exist or if 0 or -1 is requested
84  // or if row is the same as the to-be-displayed row
85  if ($additionalLanguageUid <= 0
86  || !isset($result['systemLanguageRows'][$additionalLanguageUid])
87  || $additionalLanguageUid === (int)$result['databaseRow'][$languageField]
88  ) {
89  continue;
90  }
91  $translationInfo = $translationProvider->translationInfo(
92  $tableNameWithDefaultRecords,
93  (int)$result['databaseRow'][$fieldWithUidOfDefaultRecord],
94  $additionalLanguageUid
95  );
96  if (!empty($translationInfo['translations'][$additionalLanguageUid]['uid'])) {
97  $record = BackendUtility::getRecordWSOL($result['tableName'], (int)$translationInfo['translations'][$additionalLanguageUid]['uid']);
98  $result['additionalLanguageRows'][$additionalLanguageUid] = $record;
99  }
100  }
101  }
102  }
103  }
104 
105  return $result;
106  }
107 }