TYPO3 CMS  TYPO3_7-6
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  // 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  $defaultLanguageKey = $result['tableName'] . ':' . (int)$result['databaseRow']['uid'];
73  $result['defaultLanguageDiffRow'][$defaultLanguageKey] = unserialize($result['databaseRow'][$result['processedTca']['ctrl']['transOrigDiffSourceField']]);
74  }
75 
76  // Add language overlays from further localizations if requested
77  // @todo: Permission check if user is in "restrict ot language" is missing here.
78  // @todo: The TranslationConfigurationProvider is more stupid than good for us ... invent a better translation overlay api!
79  if (!empty($result['userTsConfig']['options.']['additionalPreviewLanguages'])) {
80  $additionalLanguageUids = GeneralUtility::intExplode(',', $result['userTsConfig']['options.']['additionalPreviewLanguages'], true);
82  $translationProvider = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
83  foreach ($additionalLanguageUids as $additionalLanguageUid) {
84  // Continue if this system language record does not exist or if 0 or -1 is requested
85  // or if row is the same as the to-be-displayed row
86  if ($additionalLanguageUid <= 0
87  || !isset($result['systemLanguageRows'][$additionalLanguageUid])
88  || $additionalLanguageUid === (int)$result['databaseRow'][$languageField]
89  ) {
90  continue;
91  }
92  $translationInfo = $translationProvider->translationInfo(
93  $tableNameWithDefaultRecords,
94  (int)$result['databaseRow'][$fieldWithUidOfDefaultRecord],
95  $additionalLanguageUid
96  );
97  if (!empty($translationInfo['translations'][$additionalLanguageUid]['uid'])) {
98  $record = BackendUtility::getRecordWSOL($result['tableName'], (int)$translationInfo['translations'][$additionalLanguageUid]['uid']);
99  $result['additionalLanguageRows'][$additionalLanguageUid] = $record;
100  }
101  }
102  }
103  }
104  }
105 
106  return $result;
107  }
108 }
static intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
static getRecordWSOL($table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)