‪TYPO3CMS  11.5
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 Exception;
21 use Psr\Http\Message\ResponseInterface;
22 use Psr\Http\Message\ServerRequestInterface;
31 use TYPO3\CMS\Backend\Utility\BackendUtility;
48 
54 {
60  protected ‪$table;
61 
67  protected ‪$uid;
68 
72  protected ‪$permsClause;
73 
77  protected ‪$access = false;
78 
86  protected ‪$type = '';
87 
91  protected ‪$moduleTemplate;
92 
99  protected ‪$pageInfo;
100 
106  protected ‪$row;
107 
108  protected ?‪File ‪$fileObject = null;
109  protected ?‪Folder ‪$folderObject = null;
110 
112  protected ‪UriBuilder ‪$uriBuilder;
114 
115  public function ‪__construct(
119  ) {
120  $this->iconFactory = ‪$iconFactory;
121  $this->uriBuilder = ‪$uriBuilder;
122  $this->moduleTemplateFactory = ‪$moduleTemplateFactory;
123  }
124 
132  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
133  {
134  $this->‪init($request);
135  $this->‪main($request);
136  return new ‪HtmlResponse($this->moduleTemplate->renderContent());
137  }
138 
145  protected function ‪init(ServerRequestInterface $request): void
146  {
147  $this->moduleTemplate = $this->moduleTemplateFactory->create($request);
148  $this->moduleTemplate->getDocHeaderComponent()->disable();
149  $queryParams = $request->getQueryParams();
150 
151  $this->table = $queryParams['table'] ?? null;
152  $this->uid = $queryParams['uid'] ?? null;
153 
154  $this->permsClause = $this->‪getBackendUser()->‪getPagePermsClause(‪Permission::PAGE_SHOW);
155 
156  if (isset(‪$GLOBALS['TCA'][$this->table])) {
157  $this->‪initDatabaseRecord();
158  } elseif ($this->table === '_FILE' || $this->table === '_FOLDER' || $this->table === 'sys_file') {
159  $this->‪initFileOrFolderRecord();
160  }
161  }
162 
166  protected function ‪initDatabaseRecord(): void
167  {
168  $this->type = 'db';
169  $this->uid = (int)$this->uid;
170 
171  // Check permissions and uid value:
172  if ($this->uid && $this->‪getBackendUser()->‪check('tables_select', $this->table)) {
173  if ((string)$this->table === 'pages') {
174  $this->pageInfo = BackendUtility::readPageAccess($this->uid, $this->permsClause) ?: [];
175  $this->access = $this->pageInfo !== [];
176  $this->row = ‪$this->pageInfo;
177  } else {
178  $this->row = BackendUtility::getRecordWSOL($this->table, $this->uid);
179  if ($this->row) {
180  if (isset($this->row['_ORIG_uid'])) {
181  // Make $this->uid the uid of the versioned record, while $this->row['uid'] is live record uid
182  $this->uid = (int)$this->row['_ORIG_uid'];
183  }
184  $this->pageInfo = BackendUtility::readPageAccess((int)$this->row['pid'], $this->permsClause) ?: [];
185  $this->access = $this->pageInfo !== [];
186  }
187  }
188  }
189  }
190 
194  protected function ‪initFileOrFolderRecord(): void
195  {
196  $fileOrFolderObject = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($this->uid);
197 
198  if ($fileOrFolderObject instanceof Folder) {
199  $this->folderObject = $fileOrFolderObject;
200  $this->access = $this->folderObject->checkActionPermission('read');
201  $this->type = 'folder';
202  } elseif ($fileOrFolderObject instanceof File) {
203  $this->fileObject = $fileOrFolderObject;
204  $this->access = $this->fileObject->checkActionPermission('read');
205  $this->type = 'file';
206  $this->table = 'sys_file';
207 
208  try {
209  $this->row = BackendUtility::getRecordWSOL($this->table, $fileOrFolderObject->getUid());
210  } catch (Exception $e) {
211  $this->row = [];
212  }
213  }
214  }
215 
222  protected function ‪main(ServerRequestInterface $request): void
223  {
224  $content = '';
225 
226  // Rendering of the output via fluid
227  $view = GeneralUtility::makeInstance(StandaloneView::class);
228  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
229  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
230  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
231  'EXT:backend/Resources/Private/Templates/ContentElement/ElementInformation.html'
232  ));
233 
234  if ($this->access) {
235  // render type by user func
236  $typeRendered = false;
237  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] ?? [] as $className) {
238  $typeRenderObj = GeneralUtility::makeInstance($className);
239  if (is_object($typeRenderObj) && method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render')) {
240  if ($typeRenderObj->isValid($this->type, $this)) {
241  $content .= $typeRenderObj->render($this->type, $this);
242  $typeRendered = true;
243  break;
244  }
245  }
246  }
247 
248  if (!$typeRendered) {
249  $view->assign('accessAllowed', true);
250  $view->assignMultiple($this->‪getPageTitle());
251  $view->assignMultiple($this->‪getPreview());
252  $view->assignMultiple($this->‪getPropertiesForTable());
253  $view->assignMultiple($this->‪getReferences($request));
254  $view->assign('returnUrl', GeneralUtility::sanitizeLocalUrl($request->getQueryParams()['returnUrl'] ?? ''));
255  $view->assign('maxTitleLength', $this->‪getBackendUser()->uc['titleLen'] ?? 20);
256  $content .= $view->render();
257  }
258  } else {
259  $content .= $view->render();
260  }
261 
262  $this->moduleTemplate->setContent($content);
263  }
264 
270  protected function ‪getPageTitle(): array
271  {
272  $pageTitle = [
273  'title' => BackendUtility::getRecordTitle($this->table, $this->row),
274  ];
275  if ($this->type === 'folder') {
276  $pageTitle['title'] = htmlspecialchars($this->folderObject->getName());
277  $pageTitle['table'] = $this->‪getLanguageService()->‪sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:folder');
278  $pageTitle['icon'] = $this->iconFactory->getIconForResource($this->folderObject, ‪Icon::SIZE_SMALL)->render();
279  } elseif ($this->type === 'file') {
280  $pageTitle['table'] = $this->‪getLanguageService()->‪sL(‪$GLOBALS['TCA'][$this->table]['ctrl']['title']);
281  $pageTitle['icon'] = $this->iconFactory->getIconForResource($this->fileObject, ‪Icon::SIZE_SMALL)->render();
282  } else {
283  $pageTitle['table'] = $this->‪getLanguageService()->‪sL(‪$GLOBALS['TCA'][$this->table]['ctrl']['title']);
284  $pageTitle['icon'] = $this->iconFactory->getIconForRecord($this->table, $this->row, ‪Icon::SIZE_SMALL);
285  }
286  $this->moduleTemplate->setTitle($pageTitle['table'] . ': ' . $pageTitle['title']);
287  return $pageTitle;
288  }
289 
295  protected function ‪getPreview(): array
296  {
297  $preview = [];
298  // Perhaps @todo in future: Also display preview for records - without fileObject
299  if (!$this->fileObject) {
300  return $preview;
301  }
302 
303  // check if file is marked as missing
304  if ($this->fileObject->isMissing()) {
305  $preview['missingFile'] = $this->fileObject->getName();
306  } else {
307  ‪$rendererRegistry = GeneralUtility::makeInstance(RendererRegistry::class);
308  $fileRenderer = ‪$rendererRegistry->getRenderer($this->fileObject);
309  $preview['url'] = $this->fileObject->getPublicUrl() ?? '';
310 
311  $width = min(590, $this->fileObject->getMetaData()['width'] ?? 590) . 'm';
312  $height = min(400, $this->fileObject->getMetaData()['height'] ?? 400) . 'm';
313 
314  // Check if there is a FileRenderer
315  if ($fileRenderer !== null) {
316  $preview['fileRenderer'] = $fileRenderer->render($this->fileObject, $width, $height);
317  // else check if we can create an Image preview
318  } elseif ($this->fileObject->isImage()) {
319  $preview['fileObject'] = ‪$this->fileObject;
320  $preview['width'] = $width;
321  $preview['height'] = $height;
322  }
323  }
324  return $preview;
325  }
326 
332  protected function ‪getPropertiesForTable(): array
333  {
334  $lang = $this->‪getLanguageService();
335  $propertiesForTable = [];
336  $propertiesForTable['extraFields'] = $this->‪getExtraFields();
337 
338  // Traverse the list of fields to display for the record:
339  $fieldList = $this->‪getFieldList($this->table, (int)($this->row['uid'] ?? 0));
340 
341  foreach ($fieldList as $name) {
342  $name = trim($name);
343  ‪$uid = $this->row['uid'] ?? 0;
344 
345  if (!isset(‪$GLOBALS['TCA'][$this->table]['columns'][$name])) {
346  continue;
347  }
348 
349  // @todo Add meaningful information for mfa field. For the time being we don't display anything at all.
350  if ($this->type === 'db' && $name === 'mfa' && in_array($this->table, ['be_users', 'fe_users'], true)) {
351  continue;
352  }
353 
354  // not a real field -> skip
355  if ($this->type === 'file' && $name === 'fileinfo') {
356  continue;
357  }
358 
359  // Field does not exist (e.g. having type=none) -> skip
360  if (!array_key_exists($name, $this->row)) {
361  continue;
362  }
363 
364  $isExcluded = !(!(‪$GLOBALS['TCA'][‪$this->table]['columns'][$name]['exclude'] ?? false) || $this->‪getBackendUser()->‪check('non_exclude_fields', $this->table . ':' . $name));
365  if ($isExcluded) {
366  continue;
367  }
368  $label = $lang->sL(BackendUtility::getItemLabel($this->table, $name));
369  $label = $label ?: $name;
370 
371  $propertiesForTable['fields'][] = [
372  'fieldValue' => BackendUtility::getProcessedValue($this->table, $name, $this->row[$name], 0, false, false, ‪$uid),
373  'fieldLabel' => htmlspecialchars($label),
374  ];
375  }
376 
377  // additional information for folders and files
378  if ($this->folderObject instanceof Folder || $this->fileObject instanceof ‪File) {
379  // storage
380  if ($this->folderObject instanceof Folder) {
381  $propertiesForTable['fields']['storage'] = [
382  'fieldValue' => $this->folderObject->getStorage()->getName(),
383  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_file.storage')),
384  ];
385  }
386 
387  // folder
388  $resourceObject = $this->fileObject ?: ‪$this->folderObject;
389  $propertiesForTable['fields']['folder'] = [
390  'fieldValue' => $resourceObject->getParentFolder()->getReadablePath(),
391  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:folder')),
392  ];
393 
394  if ($this->fileObject instanceof File) {
395  // show file dimensions for images
396  if ($this->fileObject->getType() === ‪AbstractFile::FILETYPE_IMAGE) {
397  $propertiesForTable['fields']['width'] = [
398  'fieldValue' => $this->fileObject->getProperty('width') . 'px',
399  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.width')),
400  ];
401  $propertiesForTable['fields']['height'] = [
402  'fieldValue' => $this->fileObject->getProperty('height') . 'px',
403  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.height')),
404  ];
405  }
406 
407  // file size
408  $propertiesForTable['fields']['size'] = [
409  'fieldValue' => GeneralUtility::formatSize((int)$this->fileObject->getProperty('size'), htmlspecialchars($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:byteSizeUnits'))),
410  'fieldLabel' => $lang->sL(BackendUtility::getItemLabel($this->table, 'size')),
411  ];
412 
413  // show the metadata of a file as well
414  ‪$table = 'sys_file_metadata';
415  $metaDataRepository = GeneralUtility::makeInstance(MetaDataRepository::class);
417  $metaData = $metaDataRepository->findByFileUid($this->row['uid'] ?? 0);
418 
419  // If there is no metadata record, skip it
420  if ($metaData !== []) {
421  $allowedFields = $this->‪getFieldList(‪$table, (int)$metaData['uid']);
422 
423  foreach ($metaData as $name => $value) {
424  if (in_array($name, $allowedFields, true)) {
425  if (!isset(‪$GLOBALS['TCA'][‪$table]['columns'][$name])) {
426  continue;
427  }
428 
429  $isExcluded = !(!(‪$GLOBALS['TCA'][‪$table]['columns'][$name]['exclude'] ?? false) || $this->‪getBackendUser()->‪check('non_exclude_fields', ‪$table . ':' . $name));
430  if ($isExcluded) {
431  continue;
432  }
433 
434  $label = $lang->sL(BackendUtility::getItemLabel(‪$table, $name));
435  $label = $label ?: $name;
436 
437  $propertiesForTable['fields'][] = [
438  'fieldValue' => BackendUtility::getProcessedValue(‪$table, $name, $metaData[$name], 0, false, false, (int)$metaData['uid']),
439  'fieldLabel' => htmlspecialchars($label),
440  ];
441  }
442  }
443  }
444  }
445  }
446 
447  return $propertiesForTable;
448  }
449 
457  protected function ‪getFieldList(string ‪$table, int ‪$uid): array
458  {
459  $formDataGroup = GeneralUtility::makeInstance(TcaDatabaseRecord::class);
460  $formDataCompiler = GeneralUtility::makeInstance(FormDataCompiler::class, $formDataGroup);
461  $formDataCompilerInput = [
462  'command' => 'edit',
463  'tableName' => ‪$table,
464  'vanillaUid' => ‪$uid,
465  ];
466  try {
467  $result = $formDataCompiler->compile($formDataCompilerInput);
468  $fieldList = array_unique(array_values($result['columnsToProcess']));
469 
470  $ctrlKeysOfUnneededFields = ['origUid', 'transOrigPointerField', 'transOrigDiffSourceField'];
471  foreach ($ctrlKeysOfUnneededFields as $field) {
472  if (isset(‪$GLOBALS['TCA'][‪$table]['ctrl'][$field]) && ($key = array_search(‪$GLOBALS['TCA'][‪$table]['ctrl'][$field], $fieldList, true)) !== false) {
473  unset($fieldList[$key]);
474  }
475  }
476  } catch (‪Exception $exception) {
477  $fieldList = [];
478  }
479 
480  $searchFields = ‪GeneralUtility::trimExplode(',', (‪$GLOBALS['TCA'][‪$table]['ctrl']['searchFields'] ?? ''));
481 
482  return array_unique(array_merge($fieldList, $searchFields));
483  }
484 
490  protected function ‪getExtraFields(): array
491  {
492  $lang = $this->‪getLanguageService();
493  $keyLabelPair = [];
494  if (in_array($this->type, ['folder', 'file'], true)) {
495  if ($this->type === 'file') {
496  $keyLabelPair['uid'] = [
497  'value' => (int)$this->row['uid'],
498  ];
499  $keyLabelPair['creation_date'] = [
500  'value' => BackendUtility::datetime($this->row['creation_date']),
501  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.creationDate')),
502  'isDatetime' => true,
503  ];
504  $keyLabelPair['modification_date'] = [
505  'value' => BackendUtility::datetime($this->row['modification_date']),
506  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.timestamp')),
507  'isDatetime' => true,
508  ];
509  }
510  } else {
511  $keyLabelPair['uid'] = [
512  'value' => BackendUtility::getProcessedValueExtra($this->table, 'uid', $this->row['uid']),
513  'fieldLabel' => rtrim(htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:show_item.php.uid')), ':'),
514  ];
515  foreach (['crdate' => 'creationDate', 'tstamp' => 'timestamp', 'cruser_id' => 'creationUserId'] as $field => $label) {
516  if (isset(‪$GLOBALS['TCA'][$this->table]['ctrl'][$field])) {
517  if ($field === 'crdate' || $field === 'tstamp') {
518  $keyLabelPair[$field] = [
519  'value' => BackendUtility::datetime($this->row[‪$GLOBALS['TCA'][$this->table]['ctrl'][$field]]),
520  'fieldLabel' => rtrim(htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.' . $label)), ':'),
521  'isDatetime' => true,
522  ];
523  }
524  if ($field === 'cruser_id') {
525  $rowValue = BackendUtility::getProcessedValueExtra($this->table, ‪$GLOBALS['TCA'][$this->table]['ctrl'][$field], $this->row[‪$GLOBALS['TCA'][$this->table]['ctrl'][$field]]);
526  if ($rowValue) {
527  $creatorRecord = BackendUtility::getRecord('be_users', (int)$rowValue);
528  if ($creatorRecord) {
529  $avatar = GeneralUtility::makeInstance(Avatar::class);
530  $creatorRecord['icon'] = $avatar->render($creatorRecord);
531  $rowValue = $creatorRecord;
532  $keyLabelPair['creatorRecord'] = [
533  'value' => $rowValue,
534  'fieldLabel' => rtrim(htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.' . $label)), ':'),
535  ];
536  }
537  }
538  }
539  }
540  }
541  }
542  return $keyLabelPair;
543  }
544 
551  protected function ‪getReferences(ServerRequestInterface $request): array
552  {
553  $references = [];
554  switch ($this->type) {
555  case 'db': {
556  $references['refLines'] = $this->‪makeRef($this->table, $this->uid, $request);
557  $references['refFromLines'] = $this->‪makeRefFrom($this->table, $this->uid, $request);
558  break;
559  }
560 
561  case 'file': {
562  if ($this->fileObject && $this->fileObject->isIndexed()) {
563  $references['refLines'] = $this->‪makeRef('_FILE', $this->fileObject, $request);
564  }
565  break;
566  }
567  }
568  return $references;
569  }
570 
578  protected function ‪getLabelForTableColumn($tableName, $fieldName): string
579  {
580  if ((‪$GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label'] ?? null) !== null) {
581  $field = $this->‪getLanguageService()->‪sL(‪$GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label']);
582  if (trim($field) === '') {
583  $field = $fieldName;
584  }
585  } else {
586  $field = $fieldName;
587  }
588  return $field;
589  }
590 
600  protected function ‪getRecordActions(‪$table, ‪$uid, ServerRequestInterface $request): array
601  {
602  if (‪$table === '' || ‪$uid < 0) {
603  return [];
604  }
605 
606  $actions = [];
607  // Edit button
608  $urlParameters = [
609  'edit' => [
610  ‪$table => [
611  ‪$uid => 'edit',
612  ],
613  ],
614  'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri(),
615  ];
616  $actions['recordEditUrl'] = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
617 
618  // History button
619  $urlParameters = [
620  'element' => ‪$table . ':' . ‪$uid,
621  'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri(),
622  ];
623  $actions['recordHistoryUrl'] = (string)$this->uriBuilder->buildUriFromRoute('record_history', $urlParameters);
624 
625  if (‪$table === 'pages') {
626  // Recordlist button
627  $actions['webListUrl'] = (string)$this->uriBuilder->buildUriFromRoute('web_list', ['id' => ‪$uid, 'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri()]);
628 
629  $previewUriBuilder = ‪PreviewUriBuilder::create((int)‪$uid)
630  ->withRootLine(BackendUtility::BEgetRootLine(‪$uid));
631  // View page button
632  $actions['previewUrlAttributes'] = $previewUriBuilder->serializeDispatcherAttributes();
633  }
634 
635  return $actions;
636  }
637 
647  protected function ‪makeRef(‪$table, $ref, ServerRequestInterface $request): array
648  {
649  $refLines = [];
650  $lang = $this->‪getLanguageService();
651  // Files reside in sys_file table
652  if ($table === '_FILE') {
653  $selectTable = 'sys_file';
654  $selectUid = $ref->getUid();
655  } else {
656  $selectTable = ‪$table;
657  $selectUid = $ref;
658  }
659  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
660  ->getQueryBuilderForTable('sys_refindex');
661 
662  $predicates = [
663  $queryBuilder->expr()->eq(
664  'ref_table',
665  $queryBuilder->createNamedParameter($selectTable, ‪Connection::PARAM_STR)
666  ),
667  $queryBuilder->expr()->eq(
668  'ref_uid',
669  $queryBuilder->createNamedParameter($selectUid, ‪Connection::PARAM_INT)
670  ),
671  ];
672 
673  $backendUser = $this->‪getBackendUser();
674  if (!$backendUser->isAdmin()) {
675  $allowedSelectTables = ‪GeneralUtility::trimExplode(',', $backendUser->groupData['tables_select']);
676  $predicates[] = $queryBuilder->expr()->in(
677  'tablename',
678  $queryBuilder->createNamedParameter($allowedSelectTables, Connection::PARAM_STR_ARRAY)
679  );
680  }
681 
682  $rows = $queryBuilder
683  ->select('*')
684  ->from('sys_refindex')
685  ->where(...$predicates)
686  ->executeQuery()
687  ->fetchAllAssociative();
688 
689  // Compile information for title tag:
690  foreach ($rows as ‪$row) {
691  if (‪$row['tablename'] === 'sys_file_reference') {
693  if (‪$row === null) {
694  return [];
695  }
696  }
697 
698  $line = [];
699  $record = BackendUtility::getRecordWSOL(‪$row['tablename'], ‪$row['recuid']);
700  if ($record) {
701  if (!$this->‪canAccessPage($row['tablename'], $record)) {
702  continue;
703  }
704  $parentRecord = BackendUtility::getRecord('pages', $record['pid']);
705  $parentRecordTitle = is_array($parentRecord)
706  ? BackendUtility::getRecordTitle('pages', $parentRecord)
707  : '';
708  $urlParameters = [
709  'edit' => [
710  ‪$row['tablename'] => [
711  ‪$row['recuid'] => 'edit',
712  ],
713  ],
714  'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri(),
715  ];
716  $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
717  $line['url'] = $url;
718  $line['icon'] = $this->iconFactory->getIconForRecord(‪$row['tablename'], $record, ‪Icon::SIZE_SMALL)->render();
719  $line['row'] = ‪$row;
720  $line['record'] = $record;
721  $line['recordTitle'] = BackendUtility::getRecordTitle(‪$row['tablename'], $record, false, true);
722  $line['parentRecord'] = $parentRecord;
723  $line['parentRecordTitle'] = $parentRecordTitle;
724  $line['title'] = $lang->sL(‪$GLOBALS['TCA'][‪$row['tablename']]['ctrl']['title']);
725  $line['labelForTableColumn'] = $this->‪getLabelForTableColumn($row['tablename'], ‪$row['field']);
726  $line['path'] = BackendUtility::getRecordPath($record['pid'], '', 0, 0);
727  $line['actions'] = $this->‪getRecordActions($row['tablename'], ‪$row['recuid'], $request);
728  } else {
729  $line['row'] = ‪$row;
730  $line['title'] = $lang->sL(‪$GLOBALS['TCA'][‪$row['tablename']]['ctrl']['title'] ?? '') ?: ‪$row['tablename'];
731  $line['labelForTableColumn'] = $this->‪getLabelForTableColumn($row['tablename'], ‪$row['field']);
732  }
733  $refLines[] = $line;
734  }
735  return $refLines;
736  }
737 
746  protected function ‪makeRefFrom(‪$table, $ref, ServerRequestInterface $request): array
747  {
748  $refFromLines = [];
749  $lang = $this->‪getLanguageService();
750 
751  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
752  ->getQueryBuilderForTable('sys_refindex');
753 
754  $predicates = [
755  $queryBuilder->expr()->eq(
756  'tablename',
757  $queryBuilder->createNamedParameter(‪$table, ‪Connection::PARAM_STR)
758  ),
759  $queryBuilder->expr()->eq(
760  'recuid',
761  $queryBuilder->createNamedParameter($ref, ‪Connection::PARAM_INT)
762  ),
763  ];
764 
765  $backendUser = $this->‪getBackendUser();
766  if (!$backendUser->isAdmin()) {
767  $allowedSelectTables = ‪GeneralUtility::trimExplode(',', $backendUser->groupData['tables_select']);
768  $predicates[] = $queryBuilder->expr()->in(
769  'ref_table',
770  $queryBuilder->createNamedParameter($allowedSelectTables, Connection::PARAM_STR_ARRAY)
771  );
772  }
773 
774  $rows = $queryBuilder
775  ->select('*')
776  ->from('sys_refindex')
777  ->where(...$predicates)
778  ->executeQuery()
779  ->fetchAllAssociative();
780 
781  // Compile information for title tag:
782  foreach ($rows as ‪$row) {
783  $line = [];
784  $record = BackendUtility::getRecordWSOL(‪$row['ref_table'], ‪$row['ref_uid']);
785  if ($record) {
786  if (!$this->‪canAccessPage($row['ref_table'], $record)) {
787  continue;
788  }
789  $urlParameters = [
790  'edit' => [
791  ‪$row['ref_table'] => [
792  ‪$row['ref_uid'] => 'edit',
793  ],
794  ],
795  'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri(),
796  ];
797  $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
798  $line['url'] = $url;
799  $line['icon'] = $this->iconFactory->getIconForRecord(‪$row['tablename'], $record, ‪Icon::SIZE_SMALL)->render();
800  $line['row'] = ‪$row;
801  $line['record'] = $record;
802  $line['recordTitle'] = BackendUtility::getRecordTitle(‪$row['ref_table'], $record, false, true);
803  $line['title'] = $lang->sL(‪$GLOBALS['TCA'][‪$row['ref_table']]['ctrl']['title'] ?? '');
804  $line['labelForTableColumn'] = $this->‪getLabelForTableColumn($table, ‪$row['field']);
805  $line['path'] = BackendUtility::getRecordPath($record['pid'], '', 0, 0);
806  $line['actions'] = $this->‪getRecordActions($row['ref_table'], ‪$row['ref_uid'], $request);
807  } else {
808  $line['row'] = ‪$row;
809  $line['title'] = $lang->sL(‪$GLOBALS['TCA'][‪$row['ref_table']]['ctrl']['title'] ?? '');
810  $line['labelForTableColumn'] = $this->‪getLabelForTableColumn($table, ‪$row['field']);
811  }
812  $refFromLines[] = $line;
813  }
814  return $refFromLines;
815  }
816 
823  protected function ‪transformFileReferenceToRecordReference(array $referenceRecord): ?array
824  {
825  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
826  ->getQueryBuilderForTable('sys_file_reference');
827  $queryBuilder->getRestrictions()->removeAll();
828  $fileReference = $queryBuilder
829  ->select('*')
830  ->from('sys_file_reference')
831  ->where(
832  $queryBuilder->expr()->eq(
833  'uid',
834  $queryBuilder->createNamedParameter($referenceRecord['recuid'], ‪Connection::PARAM_INT)
835  )
836  )
837  ->executeQuery()
838  ->fetchAssociative();
839 
840  return $fileReference ? [
841  'recuid' => $fileReference['uid_foreign'],
842  'tablename' => $fileReference['tablenames'],
843  'field' => $fileReference['fieldname'],
844  'flexpointer' => '',
845  'softref_key' => '',
846  'sorting' => $fileReference['sorting_foreign'],
847  ] : null;
848  }
849 
855  protected function ‪canAccessPage(string $tableName, array $record): bool
856  {
857  $recordPid = (int)($tableName === 'pages' ? $record['uid'] : $record['pid']);
858  return $this->‪getBackendUser()->‪isInWebMount($tableName === 'pages' ? $record : $record['pid'])
859  || $recordPid === 0 && !empty(‪$GLOBALS['TCA'][$tableName]['ctrl']['security']['ignoreRootLevelRestriction']);
860  }
861 
866  {
867  return ‪$GLOBALS['LANG'];
868  }
869 
873  protected function ‪getBackendUser(): ‪BackendUserAuthentication
874  {
875  return ‪$GLOBALS['BE_USER'];
876  }
877 }
‪TYPO3\CMS\Core\Resource\Index\MetaDataRepository
Definition: MetaDataRepository.php:41
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$uriBuilder
‪UriBuilder $uriBuilder
Definition: ElementInformationController.php:104
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: ElementInformationController.php:85
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getPropertiesForTable
‪array getPropertiesForTable()
Definition: ElementInformationController.php:324
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:49
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$permsClause
‪string $permsClause
Definition: ElementInformationController.php:69
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getExtraFields
‪array getExtraFields()
Definition: ElementInformationController.php:482
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getPagePermsClause
‪string getPagePermsClause($perms)
Definition: BackendUserAuthentication.php:460
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: ElementInformationController.php:124
‪TYPO3\CMS\Backend\Routing\PreviewUriBuilder\create
‪static static create(int $pageId, string $alternativeUri=null)
Definition: PreviewUriBuilder.php:75
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$row
‪array $row
Definition: ElementInformationController.php:98
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:29
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getPreview
‪array getPreview()
Definition: ElementInformationController.php:287
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getPageTitle
‪array getPageTitle()
Definition: ElementInformationController.php:262
‪TYPO3\CMS\Backend\Backend\Avatar\Avatar
Definition: Avatar.php:33
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\makeRef
‪array makeRef($table, $ref, ServerRequestInterface $request)
Definition: ElementInformationController.php:639
‪TYPO3\CMS\Backend\Exception
Definition: Exception.php:23
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\transformFileReferenceToRecordReference
‪array transformFileReferenceToRecordReference(array $referenceRecord)
Definition: ElementInformationController.php:815
‪TYPO3\CMS\Backend\Controller\ContentElement
Definition: ElementHistoryController.php:16
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\check
‪bool check($type, $value)
Definition: BackendUserAuthentication.php:585
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController
Definition: ElementInformationController.php:54
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getFieldList
‪array getFieldList(string $table, int $uid)
Definition: ElementInformationController.php:449
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:161
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getLabelForTableColumn
‪string getLabelForTableColumn($tableName, $fieldName)
Definition: ElementInformationController.php:570
‪TYPO3\CMS\Core\Database\Connection\PARAM_STR
‪const PARAM_STR
Definition: Connection.php:54
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\canAccessPage
‪bool canAccessPage(string $tableName, array $record)
Definition: ElementInformationController.php:847
‪TYPO3\CMS\Core\Resource\AbstractFile\FILETYPE_IMAGE
‪const FILETYPE_IMAGE
Definition: AbstractFile.php:78
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\main
‪main(ServerRequestInterface $request)
Definition: ElementInformationController.php:214
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$table
‪string $table
Definition: ElementInformationController.php:59
‪TYPO3\CMS\Core\Resource\AbstractFile
Definition: AbstractFile.php:26
‪TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
Definition: RouteNotFoundException.php:21
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\makeRefFrom
‪array makeRefFrom($table, $ref, ServerRequestInterface $request)
Definition: ElementInformationController.php:738
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\initFileOrFolderRecord
‪initFileOrFolderRecord()
Definition: ElementInformationController.php:186
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$fileObject
‪File $fileObject
Definition: ElementInformationController.php:100
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: ElementInformationController.php:865
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\__construct
‪__construct(IconFactory $iconFactory, UriBuilder $uriBuilder, ModuleTemplateFactory $moduleTemplateFactory)
Definition: ElementInformationController.php:107
‪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\init
‪init(ServerRequestInterface $request)
Definition: ElementInformationController.php:137
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$type
‪string $type
Definition: ElementInformationController.php:81
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$iconFactory
‪IconFactory $iconFactory
Definition: ElementInformationController.php:103
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\initDatabaseRecord
‪initDatabaseRecord()
Definition: ElementInformationController.php:158
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:38
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$access
‪bool $access
Definition: ElementInformationController.php:73
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getReferences
‪array getReferences(ServerRequestInterface $request)
Definition: ElementInformationController.php:543
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$uid
‪int $uid
Definition: ElementInformationController.php:65
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Routing\PreviewUriBuilder
Definition: PreviewUriBuilder.php:32
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$folderObject
‪Folder $folderObject
Definition: ElementInformationController.php:101
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getLanguageService
‪LanguageService getLanguageService()
Definition: ElementInformationController.php:857
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$moduleTemplateFactory
‪ModuleTemplateFactory $moduleTemplateFactory
Definition: ElementInformationController.php:105
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getRecordActions
‪array getRecordActions($table, $uid, ServerRequestInterface $request)
Definition: ElementInformationController.php:592
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isInWebMount
‪int null isInWebMount($idOrRow, $readPerms='', $exitOnError=null)
Definition: BackendUserAuthentication.php:304
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Form\FormDataCompiler
Definition: FormDataCompiler.php:25
‪TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord
Definition: TcaDatabaseRecord.php:25
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$pageInfo
‪array $pageInfo
Definition: ElementInformationController.php:92
‪$rendererRegistry
‪$rendererRegistry
Definition: ext_localconf.php:48
‪TYPO3\CMS\Core\Resource\Rendering\RendererRegistry
Definition: RendererRegistry.php:26
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26