‪TYPO3CMS  ‪main
ElementInformationController.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 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
35 use TYPO3\CMS\Core\Imaging\IconSize;
45 
51 #[AsController]
53 {
57  protected string ‪$type = 'db';
58 
59  protected array ‪$row = [];
60  protected ?string ‪$table = null;
61  protected ?‪File ‪$fileObject = null;
62  protected ?‪Folder ‪$folderObject = null;
63 
64  public function ‪__construct(
65  protected readonly ‪IconFactory $iconFactory,
66  protected readonly ‪UriBuilder $uriBuilder,
67  protected readonly ‪ModuleTemplateFactory $moduleTemplateFactory,
68  protected readonly ‪ResourceFactory $resourceFactory,
69  private readonly ‪FormDataCompiler $formDataCompiler,
70  ) {}
71 
76  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
77  {
78  $backendUser = $this->‪getBackendUser();
79  $view = $this->moduleTemplateFactory->create($request);
80  $view->getDocHeaderComponent()->disable();
81  $queryParams = $request->getQueryParams();
82  $this->table = $queryParams['table'] ?? null;
83  ‪$uid = $queryParams['uid'] ?? '';
84  $permsClause = $backendUser->getPagePermsClause(‪Permission::PAGE_SHOW);
85  // Determines if table/uid point to database record or file and if user has access to view information
86  $accessAllowed = false;
87  if (isset(‪$GLOBALS['TCA'][$this->table])) {
88  ‪$uid = (int)‪$uid;
89  // Check permissions and uid value:
90  if (‪$uid && $backendUser->check('tables_select', $this->table)) {
91  if ((string)$this->table === 'pages') {
92  $this->row = BackendUtility::readPageAccess(‪$uid, $permsClause) ?: [];
93  $accessAllowed = $this->row !== [];
94  } else {
95  $this->row = BackendUtility::getRecordWSOL($this->table, ‪$uid);
96  if ($this->row) {
97  if (isset($this->row['_ORIG_uid'])) {
98  // Make $uid the uid of the versioned record, while $this->row['uid'] is live record uid
99  ‪$uid = (int)$this->row['_ORIG_uid'];
100  }
101  $pageInfo = BackendUtility::readPageAccess((int)$this->row['pid'], $permsClause) ?: [];
102  $accessAllowed = $pageInfo !== [];
103  }
104  }
105  }
106  } elseif ($this->table === '_FILE' || $this->table === '_FOLDER' || $this->table === 'sys_file') {
107  $fileOrFolderObject = $this->resourceFactory->retrieveFileOrFolderObject(‪$uid);
108  if ($fileOrFolderObject instanceof ‪Folder) {
109  $this->folderObject = $fileOrFolderObject;
110  $accessAllowed = $this->folderObject->checkActionPermission('read');
111  $this->type = 'folder';
112  } elseif ($fileOrFolderObject instanceof ‪File) {
113  $this->fileObject = $fileOrFolderObject;
114  $accessAllowed = $this->fileObject->checkActionPermission('read');
115  $this->type = 'file';
116  $this->table = 'sys_file';
117  $this->row = BackendUtility::getRecordWSOL($this->table, $fileOrFolderObject->getUid());
118  }
119  }
120 
121  // Rendering of the output via fluid
122  $view->assign('accessAllowed', $accessAllowed);
123  $view->assign('hookContent', '');
124  if (!$accessAllowed) {
125  return $view->renderResponse('ContentElement/ElementInformation');
126  }
127 
128  // render type by user func
129  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] ?? [] as $className) {
130  $typeRenderObj = GeneralUtility::makeInstance($className);
131  if (is_object($typeRenderObj) && method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render')) {
132  if ($typeRenderObj->isValid($this->type, $this)) {
133  $view->assign('hookContent', $typeRenderObj->render($this->type, $this));
134  return $view->renderResponse('ContentElement/ElementInformation');
135  }
136  }
137  }
138 
139  $pageTitle = $this->‪getPageTitle();
140  $view->setTitle($pageTitle['table'] . ': ' . $pageTitle['title']);
141  $view->assignMultiple($pageTitle);
142  $view->assignMultiple($this->‪getPreview($request));
143  $view->assignMultiple($this->‪getPropertiesForTable($request));
144  $view->assignMultiple($this->‪getReferences($request, ‪$uid));
145  $view->assign('returnUrl', GeneralUtility::sanitizeLocalUrl($request->getQueryParams()['returnUrl'] ?? ''));
146  $view->assign('maxTitleLength', $this->‪getBackendUser()->uc['titleLen'] ?? 20);
147 
148  return $view->renderResponse('ContentElement/ElementInformation');
149  }
150 
154  protected function ‪getPageTitle(): array
155  {
156  $pageTitle = [
157  'title' => BackendUtility::getRecordTitle($this->table, $this->row),
158  ];
159  if ($this->type === 'folder') {
160  $pageTitle['title'] = htmlspecialchars($this->folderObject->getName());
161  $pageTitle['table'] = $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:folder');
162  $pageTitle['icon'] = $this->iconFactory->getIconForResource($this->folderObject, IconSize::SMALL)->render();
163  } elseif ($this->type === 'file') {
164  $pageTitle['table'] = $this->‪getLanguageService()->sL(‪$GLOBALS['TCA'][$this->table]['ctrl']['title']);
165  $pageTitle['icon'] = $this->iconFactory->getIconForResource($this->fileObject, IconSize::SMALL)->render();
166  } else {
167  $pageTitle['table'] = $this->‪getLanguageService()->sL(‪$GLOBALS['TCA'][$this->table]['ctrl']['title']);
168  $pageTitle['icon'] = $this->iconFactory->getIconForRecord($this->table, $this->row, IconSize::SMALL);
169  }
170  return $pageTitle;
171  }
172 
176  protected function ‪getPreview(ServerRequestInterface $request): array
177  {
178  $preview = [];
179  // Perhaps @todo in future: Also display preview for records - without fileObject
180  if (!$this->fileObject) {
181  return $preview;
182  }
183 
184  // check if file is marked as missing
185  if ($this->fileObject->isMissing()) {
186  $preview['missingFile'] = $this->fileObject->getName();
187  } else {
188  ‪$rendererRegistry = GeneralUtility::makeInstance(RendererRegistry::class);
189  $fileRenderer = ‪$rendererRegistry->getRenderer($this->fileObject);
190  $preview['url'] = $this->fileObject->getPublicUrl() ?? '';
191 
192  // Add "edit metadata" button
193  $preview['editMetadataUrl'] = '';
194  if (($metaDataUid = $this->fileObject->getProperties()['metadata_uid'] ?? false)
195  && $this->fileObject->isIndexed()
196  && $this->fileObject->checkActionPermission('editMeta')
197  && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata')
198  ) {
199  $urlParameters = [
200  'edit' => [
201  'sys_file_metadata' => [
202  $metaDataUid => 'edit',
203  ],
204  ],
205  'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri(),
206  ];
207  $preview['editMetadataUrl'] = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
208  }
209 
210  $width = min(590, $this->fileObject->getMetaData()['width'] ?? 590) . 'm';
211  $height = min(400, $this->fileObject->getMetaData()['height'] ?? 400) . 'm';
212 
213  // Check if there is a FileRenderer
214  if ($fileRenderer !== null) {
215  $preview['fileRenderer'] = $fileRenderer->render($this->fileObject, $width, $height);
216  // else check if we can create an Image preview
217  } elseif ($this->fileObject->isImage()) {
218  $preview['fileObject'] = ‪$this->fileObject;
219  $preview['width'] = $width;
220  $preview['height'] = $height;
221  }
222  }
223  return $preview;
224  }
225 
229  protected function ‪getPropertiesForTable(ServerRequestInterface $request): array
230  {
231  $lang = $this->‪getLanguageService();
232  $propertiesForTable = [];
233  $propertiesForTable['extraFields'] = $this->‪getExtraFields();
234 
235  // Traverse the list of fields to display for the record:
236  $fieldList = $this->‪getFieldList($request, $this->table, (int)($this->row['uid'] ?? 0));
237 
238  foreach ($fieldList as ‪$name) {
239  ‪$name = trim(‪$name);
240  ‪$uid = $this->row['uid'] ?? 0;
241 
242  if (!isset(‪$GLOBALS['TCA'][$this->table]['columns'][‪$name])) {
243  continue;
244  }
245 
246  // @todo Add meaningful information for mfa field. For the time being we don't display anything at all.
247  if ($this->type === 'db' && ‪$name === 'mfa' && in_array($this->table, ['be_users', 'fe_users'], true)) {
248  continue;
249  }
250 
251  // not a real field -> skip
252  if ($this->type === 'file' && ‪$name === 'fileinfo') {
253  continue;
254  }
255 
256  // Field does not exist (e.g. having type=none) -> skip
257  if (!array_key_exists(‪$name, $this->row)) {
258  continue;
259  }
260 
261  $isExcluded = !(!(‪$GLOBALS['TCA'][‪$this->table]['columns'][‪$name]['exclude'] ?? false) || $this->‪getBackendUser()->check('non_exclude_fields', $this->table . ':' . ‪$name));
262  if ($isExcluded) {
263  continue;
264  }
265  $label = $lang->sL(BackendUtility::getItemLabel($this->table, ‪$name));
266  $label = $label ?: ‪$name;
267 
268  $propertiesForTable['fields'][] = [
269  'fieldValue' => BackendUtility::getProcessedValue($this->table, ‪$name, $this->row[‪$name], 0, false, false, ‪$uid),
270  'fieldLabel' => htmlspecialchars($label),
271  ];
272  }
273 
274  // additional information for folders and files
275  if ($this->folderObject instanceof ‪Folder || $this->fileObject instanceof ‪File) {
276  // storage
277  if ($this->folderObject instanceof ‪Folder) {
278  $propertiesForTable['fields']['storage'] = [
279  'fieldValue' => $this->folderObject->getStorage()->getName(),
280  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_file.storage')),
281  ];
282  }
283 
284  // folder
285  $resourceObject = $this->fileObject ?: ‪$this->folderObject;
286  $parentFolder = $resourceObject->‪getParentFolder();
287  $propertiesForTable['fields']['folder'] = [
288  'fieldValue' => $parentFolder instanceof ‪Folder ? $parentFolder->‪getReadablePath() : '',
289  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:folder')),
290  ];
291 
292  if ($this->fileObject instanceof ‪File) {
293  // show file dimensions for images
294  if ($this->fileObject->isType(FileType::IMAGE)) {
295  $propertiesForTable['fields']['width'] = [
296  'fieldValue' => $this->fileObject->getProperty('width') . 'px',
297  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.width')),
298  ];
299  $propertiesForTable['fields']['height'] = [
300  'fieldValue' => $this->fileObject->getProperty('height') . 'px',
301  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.height')),
302  ];
303  }
304 
305  // file size
306  $propertiesForTable['fields']['size'] = [
307  'fieldValue' => GeneralUtility::formatSize((int)$this->fileObject->getProperty('size'), htmlspecialchars($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:byteSizeUnits'))),
308  'fieldLabel' => $lang->sL(BackendUtility::getItemLabel($this->table, 'size')),
309  ];
310 
311  // show the metadata of a file as well
312  ‪$table = 'sys_file_metadata';
313  $metaDataRepository = GeneralUtility::makeInstance(MetaDataRepository::class);
315  $metaData = $metaDataRepository->findByFileUid($this->row['uid'] ?? 0);
316 
317  // If there is no metadata record, skip it
318  if ($metaData !== []) {
319  $allowedFields = $this->‪getFieldList($request, ‪$table, (int)$metaData['uid']);
320 
321  foreach ($metaData as ‪$name => $value) {
322  if (in_array(‪$name, $allowedFields, true)) {
323  if (!isset(‪$GLOBALS['TCA'][‪$table]['columns'][‪$name])) {
324  continue;
325  }
326 
327  $isExcluded = !(!(‪$GLOBALS['TCA'][‪$table]['columns'][‪$name]['exclude'] ?? false) || $this->‪getBackendUser()->check('non_exclude_fields', $table . ':' . ‪$name));
328  if ($isExcluded) {
329  continue;
330  }
331 
332  $label = $lang->sL(BackendUtility::getItemLabel(‪$table, ‪$name));
333  $label = $label ?: ‪$name;
334 
335  $propertiesForTable['fields'][] = [
336  'fieldValue' => BackendUtility::getProcessedValue(‪$table, ‪$name, $metaData[‪$name], 0, false, false, (int)$metaData['uid']),
337  'fieldLabel' => htmlspecialchars($label),
338  ];
339  }
340  }
341  }
342  }
343  }
344 
345  return $propertiesForTable;
346  }
347 
351  protected function ‪getFieldList(ServerRequestInterface $request, string ‪$table, int ‪$uid): array
352  {
353  $formDataCompilerInput = [
354  'request' => $request,
355  'command' => 'edit',
356  'tableName' => ‪$table,
357  'vanillaUid' => ‪$uid,
358  ];
359  try {
360  $result = $this->formDataCompiler->compile($formDataCompilerInput, GeneralUtility::makeInstance(TcaDatabaseRecord::class));
361  $fieldList = array_unique(array_values($result['columnsToProcess']));
362 
363  $ctrlKeysOfUnneededFields = ['origUid', 'transOrigPointerField', 'transOrigDiffSourceField'];
364  foreach ($ctrlKeysOfUnneededFields as $field) {
365  if (isset(‪$GLOBALS['TCA'][‪$table]['ctrl'][$field]) && ($key = array_search(‪$GLOBALS['TCA'][‪$table]['ctrl'][$field], $fieldList, true)) !== false) {
366  unset($fieldList[$key]);
367  }
368  }
369  } catch (\‪Exception $exception) {
370  $fieldList = [];
371  }
372 
373  $searchFields = ‪GeneralUtility::trimExplode(',', (‪$GLOBALS['TCA'][‪$table]['ctrl']['searchFields'] ?? ''));
374 
375  return array_unique(array_merge($fieldList, $searchFields));
376  }
377 
381  protected function ‪getExtraFields(): array
382  {
383  $lang = $this->‪getLanguageService();
384  $keyLabelPair = [];
385  if (in_array($this->type, ['folder', 'file'], true)) {
386  if ($this->type === 'file') {
387  $keyLabelPair['uid'] = [
388  'value' => (int)$this->row['uid'],
389  ];
390  $keyLabelPair['creation_date'] = [
391  'value' => BackendUtility::datetime($this->row['creation_date']),
392  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.creationDate')),
393  'isDatetime' => true,
394  ];
395  $keyLabelPair['modification_date'] = [
396  'value' => BackendUtility::datetime($this->row['modification_date']),
397  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.timestamp')),
398  'isDatetime' => true,
399  ];
400  }
401  } else {
402  $keyLabelPair['uid'] = [
403  'value' => BackendUtility::getProcessedValueExtra($this->table, 'uid', $this->row['uid']),
404  'fieldLabel' => rtrim(htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:show_item.php.uid')), ':'),
405  ];
406  foreach (['crdate' => 'creationDate', 'tstamp' => 'timestamp'] as $field => $label) {
407  if (isset(‪$GLOBALS['TCA'][$this->table]['ctrl'][$field])) {
408  $keyLabelPair[$field] = [
409  'value' => BackendUtility::datetime($this->row[‪$GLOBALS['TCA'][$this->table]['ctrl'][$field]]),
410  'fieldLabel' => rtrim(htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.' . $label)), ':'),
411  'isDatetime' => true,
412  ];
413  }
414  }
415  // Show the user who created the record
416  $recordHistory = GeneralUtility::makeInstance(RecordHistory::class);
417  $ownerInformation = $recordHistory->getCreationInformationForRecord($this->table, $this->row);
418  $ownerUid = (int)(is_array($ownerInformation) && $ownerInformation['usertype'] === 'BE' ? $ownerInformation['userid'] : 0);
419  if ($ownerUid) {
420  $creatorRecord = BackendUtility::getRecord('be_users', $ownerUid);
421  if ($creatorRecord) {
422  $keyLabelPair['creatorRecord'] = [
423  'value' => $creatorRecord,
424  'fieldLabel' => rtrim(htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.creationUserId')), ':'),
425  ];
426  }
427  }
428  }
429  return $keyLabelPair;
430  }
431 
435  protected function ‪getReferences(ServerRequestInterface $request, int|string ‪$uid): array
436  {
437  $references = [];
438  switch ($this->type) {
439  case 'db': {
440  $references['refLines'] = $this->‪makeRef($this->table, ‪$uid, $request);
441  $references['refFromLines'] = $this->‪makeRefFrom($this->table, ‪$uid, $request);
442  break;
443  }
444  case 'file': {
445  if ($this->fileObject && $this->fileObject->isIndexed()) {
446  $references['refLines'] = $this->‪makeRef('_FILE', $this->fileObject, $request);
447  }
448  break;
449  }
450  }
451  return $references;
452  }
453 
461  protected function ‪getLabelForTableColumn($tableName, $fieldName): string
462  {
463  if ((‪$GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label'] ?? null) !== null) {
464  $field = $this->‪getLanguageService()->sL(‪$GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label']);
465  if (trim($field) === '') {
466  $field = $fieldName;
467  }
468  } else {
469  $field = $fieldName;
470  }
471  return $field;
472  }
473 
481  protected function ‪getRecordActions(‪$table, ‪$uid, ServerRequestInterface $request): array
482  {
483  if (‪$table === '' || ‪$uid < 0) {
484  return [];
485  }
486 
487  $actions = [];
488  // Edit button
489  $urlParameters = [
490  'edit' => [
491  ‪$table => [
492  ‪$uid => 'edit',
493  ],
494  ],
495  'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri(),
496  ];
497  $actions['recordEditUrl'] = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
498 
499  // History button
500  $urlParameters = [
501  'element' => ‪$table . ':' . ‪$uid,
502  'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri(),
503  ];
504  $actions['recordHistoryUrl'] = (string)$this->uriBuilder->buildUriFromRoute('record_history', $urlParameters);
505 
506  if (‪$table === 'pages') {
507  // Recordlist button
508  $actions['webListUrl'] = (string)$this->uriBuilder->buildUriFromRoute('web_list', ['id' => ‪$uid, 'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri()]);
509 
510  $previewUriBuilder = ‪PreviewUriBuilder::create((int)‪$uid)
511  ->withRootLine(BackendUtility::BEgetRootLine(‪$uid));
512  // View page button
513  $actions['previewUrlAttributes'] = $previewUriBuilder->serializeDispatcherAttributes();
514  }
515 
516  return $actions;
517  }
518 
526  protected function ‪makeRef(‪$table, $ref, ServerRequestInterface $request): array
527  {
528  $refLines = [];
529  $lang = $this->‪getLanguageService();
530  // Files reside in sys_file table
531  if ($table === '_FILE') {
532  $selectTable = 'sys_file';
533  $selectUid = $ref->getUid();
534  } else {
535  $selectTable = ‪$table;
536  $selectUid = $ref;
537  }
538  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
539  ->getQueryBuilderForTable('sys_refindex');
540 
541  $predicates = [
542  $queryBuilder->expr()->eq(
543  'ref_table',
544  $queryBuilder->createNamedParameter($selectTable)
545  ),
546  $queryBuilder->expr()->eq(
547  'ref_uid',
548  $queryBuilder->createNamedParameter($selectUid, ‪Connection::PARAM_INT)
549  ),
550  ];
551 
552  $backendUser = $this->‪getBackendUser();
553  if (!$backendUser->isAdmin()) {
554  $allowedSelectTables = ‪GeneralUtility::trimExplode(',', $backendUser->groupData['tables_select']);
555  $predicates[] = $queryBuilder->expr()->in(
556  'tablename',
557  $queryBuilder->createNamedParameter($allowedSelectTables, ‪Connection::PARAM_STR_ARRAY)
558  );
559  }
560 
561  $rows = $queryBuilder
562  ->select('*')
563  ->from('sys_refindex')
564  ->where(...$predicates)
565  ->executeQuery()
566  ->fetchAllAssociative();
567 
568  // Compile information for title tag:
569  foreach ($rows as ‪$row) {
570  if (‪$row['tablename'] === 'sys_file_reference') {
572  if (‪$row === null) {
573  return [];
574  }
575  }
576 
577  $line = [];
578  ‪$record = BackendUtility::getRecordWSOL(‪$row['tablename'], ‪$row['recuid']);
579  if (‪$record) {
580  if (!$this->‪canAccessPage($row['tablename'], ‪$record)) {
581  continue;
582  }
583  $parentRecord = BackendUtility::getRecord('pages', ‪$record['pid']);
584  $parentRecordTitle = is_array($parentRecord)
585  ? BackendUtility::getRecordTitle('pages', $parentRecord)
586  : '';
587  $urlParameters = [
588  'edit' => [
589  ‪$row['tablename'] => [
590  ‪$row['recuid'] => 'edit',
591  ],
592  ],
593  'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri(),
594  ];
595  ‪$url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
596  $line['url'] = ‪$url;
597  $line['icon'] = $this->iconFactory->getIconForRecord(‪$row['tablename'], ‪$record, IconSize::SMALL)->render();
598  $line['row'] = ‪$row;
599  $line['record'] = ‪$record;
600  $line['recordTitle'] = BackendUtility::getRecordTitle(‪$row['tablename'], ‪$record, false, true);
601  $line['parentRecord'] = $parentRecord;
602  $line['parentRecordTitle'] = $parentRecordTitle;
603  $line['title'] = $lang->sL(‪$GLOBALS['TCA'][‪$row['tablename']]['ctrl']['title']);
604  $line['labelForTableColumn'] = $this->‪getLabelForTableColumn($row['tablename'], ‪$row['field']);
605  $line['path'] = BackendUtility::getRecordPath(‪$record['pid'], '', 0, 0);
606  $line['actions'] = $this->‪getRecordActions($row['tablename'], ‪$row['recuid'], $request);
607  } else {
608  $line['row'] = ‪$row;
609  $line['title'] = $lang->sL(‪$GLOBALS['TCA'][‪$row['tablename']]['ctrl']['title'] ?? '') ?: ‪$row['tablename'];
610  $line['labelForTableColumn'] = $this->‪getLabelForTableColumn($row['tablename'], ‪$row['field']);
611  }
612  $refLines[] = $line;
613  }
614  return $refLines;
615  }
616 
623  protected function ‪makeRefFrom(‪$table, $ref, ServerRequestInterface $request): array
624  {
625  $refFromLines = [];
626  $lang = $this->‪getLanguageService();
627 
628  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
629  ->getQueryBuilderForTable('sys_refindex');
630 
631  $predicates = [
632  $queryBuilder->expr()->eq(
633  'tablename',
634  $queryBuilder->createNamedParameter(‪$table)
635  ),
636  $queryBuilder->expr()->eq(
637  'recuid',
638  $queryBuilder->createNamedParameter($ref, ‪Connection::PARAM_INT)
639  ),
640  ];
641 
642  $backendUser = $this->‪getBackendUser();
643  if (!$backendUser->isAdmin()) {
644  $allowedSelectTables = ‪GeneralUtility::trimExplode(',', $backendUser->groupData['tables_select']);
645  $predicates[] = $queryBuilder->expr()->in(
646  'ref_table',
647  $queryBuilder->createNamedParameter($allowedSelectTables, ‪Connection::PARAM_STR_ARRAY)
648  );
649  }
650 
651  $rows = $queryBuilder
652  ->select('*')
653  ->from('sys_refindex')
654  ->where(...$predicates)
655  ->executeQuery()
656  ->fetchAllAssociative();
657 
658  // Compile information for title tag:
659  foreach ($rows as ‪$row) {
660  $line = [];
661  ‪$record = BackendUtility::getRecordWSOL(‪$row['ref_table'], ‪$row['ref_uid']);
662  if (‪$record) {
663  if (!$this->‪canAccessPage($row['ref_table'], ‪$record)) {
664  continue;
665  }
666  $urlParameters = [
667  'edit' => [
668  ‪$row['ref_table'] => [
669  ‪$row['ref_uid'] => 'edit',
670  ],
671  ],
672  'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri(),
673  ];
674  ‪$url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
675  $line['url'] = ‪$url;
676  $line['icon'] = $this->iconFactory->getIconForRecord(‪$row['ref_table'], ‪$record, IconSize::SMALL)->render();
677  $line['row'] = ‪$row;
678  $line['record'] = ‪$record;
679  $line['recordTitle'] = BackendUtility::getRecordTitle(‪$row['ref_table'], ‪$record, false, true);
680  $line['title'] = $lang->sL(‪$GLOBALS['TCA'][‪$row['ref_table']]['ctrl']['title'] ?? '');
681  $line['labelForTableColumn'] = $this->‪getLabelForTableColumn($table, ‪$row['field']);
682  $line['path'] = BackendUtility::getRecordPath(‪$record['pid'], '', 0, 0);
683  $line['actions'] = $this->‪getRecordActions($row['ref_table'], ‪$row['ref_uid'], $request);
684  } else {
685  $line['row'] = ‪$row;
686  $line['title'] = $lang->sL(‪$GLOBALS['TCA'][‪$row['ref_table']]['ctrl']['title'] ?? '');
687  $line['labelForTableColumn'] = $this->‪getLabelForTableColumn($table, ‪$row['field']);
688  }
689  $refFromLines[] = $line;
690  }
691  return $refFromLines;
692  }
693 
697  protected function ‪transformFileReferenceToRecordReference(array $referenceRecord): ?array
698  {
699  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
700  ->getQueryBuilderForTable('sys_file_reference');
701  $queryBuilder->getRestrictions()->removeAll();
702  $fileReference = $queryBuilder
703  ->select('*')
704  ->from('sys_file_reference')
705  ->where(
706  $queryBuilder->expr()->eq(
707  'uid',
708  $queryBuilder->createNamedParameter($referenceRecord['recuid'], ‪Connection::PARAM_INT)
709  )
710  )
711  ->executeQuery()
712  ->fetchAssociative();
713 
714  return $fileReference ? [
715  'recuid' => $fileReference['uid_foreign'],
716  'tablename' => $fileReference['tablenames'],
717  'field' => $fileReference['fieldname'],
718  'flexpointer' => '',
719  'softref_key' => '',
720  'sorting' => $fileReference['sorting_foreign'],
721  ] : null;
722  }
723 
728  protected function ‪canAccessPage(string $tableName, array ‪$record): bool
729  {
730  $recordPid = (int)($tableName === 'pages' ? ‪$record['uid'] : ‪$record['pid']);
731  return $this->‪getBackendUser()->isInWebMount($tableName === 'pages' ? ‪$record : ‪$record['pid'])
732  || $recordPid === 0 && !empty(‪$GLOBALS['TCA'][$tableName]['ctrl']['security']['ignoreRootLevelRestriction']);
733  }
734 
736  {
737  return ‪$GLOBALS['LANG'];
738  }
739 
741  {
742  return ‪$GLOBALS['BE_USER'];
743  }
744 }
‪TYPO3\CMS\Core\Resource\Index\MetaDataRepository
Definition: MetaDataRepository.php:40
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getLanguageService
‪getLanguageService()
Definition: ElementInformationController.php:735
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getPropertiesForTable
‪getPropertiesForTable(ServerRequestInterface $request)
Definition: ElementInformationController.php:229
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:52
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$row
‪array $row
Definition: ElementInformationController.php:59
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:35
‪TYPO3\CMS\Backend\Exception
Definition: Exception.php:23
‪TYPO3\CMS\Backend\Controller\ContentElement
Definition: ElementHistoryController.php:18
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getBackendUser
‪getBackendUser()
Definition: ElementInformationController.php:740
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\canAccessPage
‪canAccessPage(string $tableName, array $record)
Definition: ElementInformationController.php:728
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getExtraFields
‪getExtraFields()
Definition: ElementInformationController.php:381
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController
Definition: ElementInformationController.php:53
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getPageTitle
‪getPageTitle()
Definition: ElementInformationController.php:154
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getLabelForTableColumn
‪string getLabelForTableColumn($tableName, $fieldName)
Definition: ElementInformationController.php:461
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getReferences
‪getReferences(ServerRequestInterface $request, int|string $uid)
Definition: ElementInformationController.php:435
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\makeRef
‪makeRef($table, $ref, ServerRequestInterface $request)
Definition: ElementInformationController.php:526
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Core\Resource\Folder\getParentFolder
‪getParentFolder()
Definition: Folder.php:553
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$table
‪string $table
Definition: ElementInformationController.php:60
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\makeRefFrom
‪makeRefFrom($table, $ref, ServerRequestInterface $request)
Definition: ElementInformationController.php:623
‪TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
Definition: RouteNotFoundException.php:21
‪TYPO3\CMS\Backend\History\RecordHistory
Definition: RecordHistory.php:32
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Core\Database\Connection\PARAM_STR_ARRAY
‪const PARAM_STR_ARRAY
Definition: Connection.php:77
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:38
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:42
‪TYPO3\CMS\Backend\Routing\PreviewUriBuilder\create
‪static static create(int $pageId)
Definition: PreviewUriBuilder.php:65
‪$name
‪$name
Definition: phpIntegrityChecker.php:235
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:26
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$fileObject
‪File $fileObject
Definition: ElementInformationController.php:61
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:35
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$type
‪string $type
Definition: ElementInformationController.php:57
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\__construct
‪__construct(protected readonly IconFactory $iconFactory, protected readonly UriBuilder $uriBuilder, protected readonly ModuleTemplateFactory $moduleTemplateFactory, protected readonly ResourceFactory $resourceFactory, private readonly FormDataCompiler $formDataCompiler,)
Definition: ElementInformationController.php:64
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\mainAction
‪mainAction(ServerRequestInterface $request)
Definition: ElementInformationController.php:76
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:41
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getFieldList
‪getFieldList(ServerRequestInterface $request, string $table, int $uid)
Definition: ElementInformationController.php:351
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getPreview
‪getPreview(ServerRequestInterface $request)
Definition: ElementInformationController.php:176
‪TYPO3\CMS\Webhooks\Message\$url
‪identifier readonly UriInterface $url
Definition: LoginErrorOccurredMessage.php:36
‪TYPO3\CMS\Core\Resource\Folder\getReadablePath
‪string getReadablePath($rootId=null)
Definition: Folder.php:101
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Routing\PreviewUriBuilder
Definition: PreviewUriBuilder.php:44
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$folderObject
‪Folder $folderObject
Definition: ElementInformationController.php:62
‪TYPO3\CMS\Backend\Attribute\AsController
Definition: AsController.php:25
‪TYPO3\CMS\Core\Resource\FileType
‪FileType
Definition: FileType.php:21
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Form\FormDataCompiler
Definition: FormDataCompiler.php:26
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\transformFileReferenceToRecordReference
‪transformFileReferenceToRecordReference(array $referenceRecord)
Definition: ElementInformationController.php:697
‪TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord
Definition: TcaDatabaseRecord.php:25
‪$rendererRegistry
‪$rendererRegistry
Definition: ext_localconf.php:44
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getRecordActions
‪getRecordActions($table, $uid, ServerRequestInterface $request)
Definition: ElementInformationController.php:481
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:822
‪TYPO3\CMS\Core\Resource\Rendering\RendererRegistry
Definition: RendererRegistry.php:23