‪TYPO3CMS  ‪main
DownloadRecordList.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
24 
35 {
38 
40  {
41  $this->recordList = ‪$recordList;
42  $this->translationConfigurationProvider = ‪$translationConfigurationProvider;
43  }
44 
51  public function ‪getHeaderRow(array $columnsToRender): array
52  {
53  $columnsToRender = array_combine($columnsToRender, $columnsToRender);
54  $hooks = ‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['customizeCsvHeader'] ?? [];
55  if (!empty($hooks)) {
56  trigger_error(
57  'The hook $GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][\'TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\'][\'customizeCsvHeader\'] is deprecated and will be removed in TYPO3 v14. Use PSR-14 event TYPO3\CMS\Backend\RecordList\Event\BeforeRecordDownloadIsExecutedEvent instead.',
58  E_USER_DEPRECATED
59  );
60  $hookParameters = [
61  'fields' => &$columnsToRender,
62  ];
63  foreach ($hooks as $hookFunction) {
64  GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this->recordList);
65  }
66  }
67  return $columnsToRender;
68  }
69 
80  public function ‪getRecords(
81  string $table,
82  array $columnsToRender,
83  ‪BackendUserAuthentication $backendUser,
84  bool $hideTranslations = false,
85  bool $rawValues = false
86  ): array {
87  // Creating the list of fields to include in the SQL query
88  $selectFields = $this->recordList->getFieldsToSelect($table, $columnsToRender);
89  $queryResult = $this->recordList->getQueryBuilder($table, $selectFields)->executeQuery();
90  $l10nEnabled = BackendUtility::isTableLocalizable($table);
91  $result = [];
92  // Render items
93  while ($row = $queryResult->fetchAssociative()) {
94  // In offline workspace, look for alternative record
95  BackendUtility::workspaceOL($table, $row, $backendUser->workspace, true);
96  if (!is_array($row)) {
97  continue;
98  }
99  $result[] = $this->‪prepareRow($table, $row, $columnsToRender, $this->recordList->id, $rawValues);
100  if (!$l10nEnabled) {
101  continue;
102  }
103  if ($hideTranslations) {
104  continue;
105  }
106  // Guard clause so we can quickly return if a record is localized to "all languages"
107  // It should only be possible to localize a record off default (uid 0)
108  if ((int)$row[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']] === -1) {
109  continue;
110  }
111  $translationsRaw = $this->translationConfigurationProvider->translationInfo($table, $row['uid'], 0, $row, $selectFields);
112  foreach ($translationsRaw['translations'] ?? [] as $languageId => $translationRow) {
113  // In offline workspace, look for alternative record
114  BackendUtility::workspaceOL($table, $translationRow, $backendUser->workspace, true);
115  if (is_array($translationRow) && $backendUser->‪checkLanguageAccess($languageId)) {
116  $result[] = $this->‪prepareRow($table, $translationRow, $columnsToRender, $this->recordList->id, $rawValues);
117  }
118  }
119  }
120  return $result;
121  }
122 
134  protected function ‪prepareRow(string $table, array $row, array $columnsToRender, int $pageId, bool $rawValues): array
135  {
136  foreach ($columnsToRender as $columnName) {
137  if (!$rawValues) {
138  if ($columnName === ‪$GLOBALS['TCA'][$table]['ctrl']['label']) {
139  $row[$columnName] = BackendUtility::getRecordTitle($table, $row);
140  } elseif ($columnName !== 'pid') {
141  $row[$columnName] = BackendUtility::getProcessedValueExtra($table, $columnName, $row[$columnName], 0, $row['uid']);
142  }
143  }
144  }
145  $hooks = ‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['customizeCsvRow'] ?? [];
146  if (!empty($hooks)) {
147  trigger_error(
148  'The hook $GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][\'TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\'][\'customizeCsvRow\'] is deprecated and will be removed in TYPO3 v14. Use PSR-14 event TYPO3\CMS\Backend\RecordList\Event\BeforeRecordDownloadIsExecutedEvent instead.',
149  E_USER_DEPRECATED
150  );
151 
152  $hookParameters = [
153  'databaseRow' => &$row,
154  'tableName' => $table,
155  'pageId' => $pageId,
156  ];
157  foreach ($hooks as $hookFunction) {
158  GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this->recordList);
159  }
160  }
161  return array_intersect_key($row, array_flip($columnsToRender));
162  }
163 }
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList\getHeaderRow
‪array getHeaderRow(array $columnsToRender)
Definition: DownloadRecordList.php:51
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList\prepareRow
‪array prepareRow(string $table, array $row, array $columnsToRender, int $pageId, bool $rawValues)
Definition: DownloadRecordList.php:134
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList
Definition: DownloadRecordList.php:35
‪TYPO3\CMS\Backend\RecordList\DatabaseRecordList
Definition: DatabaseRecordList.php:72
‪TYPO3\CMS\Backend\RecordList
Definition: DatabaseRecordList.php:18
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList\$recordList
‪DatabaseRecordList $recordList
Definition: DownloadRecordList.php:36
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList\__construct
‪__construct(DatabaseRecordList $recordList, TranslationConfigurationProvider $translationConfigurationProvider)
Definition: DownloadRecordList.php:39
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\checkLanguageAccess
‪bool checkLanguageAccess($langValue)
Definition: BackendUserAuthentication.php:561
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
Definition: TranslationConfigurationProvider.php:39
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList\$translationConfigurationProvider
‪TranslationConfigurationProvider $translationConfigurationProvider
Definition: DownloadRecordList.php:37
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList\getRecords
‪array[] getRecords(string $table, array $columnsToRender, BackendUserAuthentication $backendUser, bool $hideTranslations=false, bool $rawValues=false)
Definition: DownloadRecordList.php:80