‪TYPO3CMS  10.4
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 Doctrine\DBAL\Connection;
21 use Exception;
22 use Psr\Http\Message\ResponseInterface;
23 use Psr\Http\Message\ServerRequestInterface;
46 
52 {
58  protected ‪$table;
59 
65  protected ‪$uid;
66 
70  protected ‪$permsClause;
71 
75  protected ‪$access = false;
76 
84  protected ‪$type = '';
85 
89  protected ‪$moduleTemplate;
90 
97  protected ‪$pageInfo;
98 
104  protected ‪$row;
105 
109  protected ‪$fileObject;
110 
114  protected ‪$folderObject;
115 
119  protected ‪$iconFactory;
120 
124  public function ‪__construct()
125  {
126  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
127  }
128 
136  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
137  {
138  $this->‪init($request);
139  $this->‪main($request);
140  return new ‪HtmlResponse($this->moduleTemplate->renderContent());
141  }
142 
149  protected function ‪init(ServerRequestInterface $request): void
150  {
151  $queryParams = $request->getQueryParams();
152 
153  $this->table = $queryParams['table'] ?? null;
154  $this->uid = $queryParams['uid'] ?? null;
155 
156  $this->permsClause = $this->‪getBackendUser()->‪getPagePermsClause(‪Permission::PAGE_SHOW);
157  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
158  $this->moduleTemplate->getDocHeaderComponent()->disable();
159 
160  if (isset(‪$GLOBALS['TCA'][$this->table])) {
161  $this->‪initDatabaseRecord();
162  } elseif ($this->table === '_FILE' || $this->table === '_FOLDER' || $this->table === 'sys_file') {
163  $this->‪initFileOrFolderRecord();
164  }
165  }
166 
170  protected function ‪initDatabaseRecord(): void
171  {
172  $this->type = 'db';
173  $this->uid = (int)$this->uid;
174 
175  // Check permissions and uid value:
176  if ($this->uid && $this->‪getBackendUser()->‪check('tables_select', $this->table)) {
177  if ((string)$this->table === 'pages') {
178  $this->pageInfo = ‪BackendUtility::readPageAccess($this->uid, $this->permsClause);
179  $this->access = is_array($this->pageInfo);
180  $this->row = ‪$this->pageInfo;
181  } else {
182  $this->row = ‪BackendUtility::getRecordWSOL($this->table, $this->uid);
183  if ($this->row) {
184  if (!empty($this->row['t3ver_oid'])) {
185  // Make $this->uid the uid of the versioned record, while $this->row['uid'] is live record uid
186  $this->uid = (int)$this->row['_ORIG_uid'];
187  }
188  $this->pageInfo = ‪BackendUtility::readPageAccess((int)$this->row['pid'], $this->permsClause);
189  $this->access = is_array($this->pageInfo);
190  }
191  }
192  }
193  }
194 
198  protected function ‪initFileOrFolderRecord(): void
199  {
200  $fileOrFolderObject = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($this->uid);
201 
202  if ($fileOrFolderObject instanceof Folder) {
203  $this->folderObject = $fileOrFolderObject;
204  $this->access = $this->folderObject->checkActionPermission('read');
205  $this->type = 'folder';
206  } elseif ($fileOrFolderObject instanceof File) {
207  $this->fileObject = $fileOrFolderObject;
208  $this->access = $this->fileObject->checkActionPermission('read');
209  $this->type = 'file';
210  $this->table = 'sys_file';
211 
212  try {
213  $this->row = ‪BackendUtility::getRecordWSOL($this->table, $fileOrFolderObject->getUid());
214  } catch (Exception $e) {
215  $this->row = [];
216  }
217  }
218  }
219 
226  protected function ‪main(ServerRequestInterface $request): void
227  {
228  $content = '';
229 
230  // Rendering of the output via fluid
231  $view = GeneralUtility::makeInstance(StandaloneView::class);
232  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
233  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
234  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
235  'EXT:backend/Resources/Private/Templates/ContentElement/ElementInformation.html'
236  ));
237 
238  if ($this->access) {
239  // render type by user func
240  $typeRendered = false;
241  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] ?? [] as $className) {
242  $typeRenderObj = GeneralUtility::makeInstance($className);
243  if (is_object($typeRenderObj) && method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render')) {
244  if ($typeRenderObj->isValid($this->type, $this)) {
245  $content .= $typeRenderObj->render($this->type, $this);
246  $typeRendered = true;
247  break;
248  }
249  }
250  }
251 
252  if (!$typeRendered) {
253  $view->assign('accessAllowed', true);
254  $view->assignMultiple($this->‪getPageTitle());
255  $view->assignMultiple($this->‪getPreview());
256  $view->assignMultiple($this->‪getPropertiesForTable());
257  $view->assignMultiple($this->‪getReferences($request));
258  $view->assign('returnUrl', GeneralUtility::sanitizeLocalUrl($request->getQueryParams()['returnUrl']));
259  $view->assign('maxTitleLength', $this->‪getBackendUser()->uc['titleLen'] ?? 20);
260  $content .= $view->render();
261  }
262  } else {
263  $content .= $view->render();
264  }
265 
266  $this->moduleTemplate->setContent($content);
267  }
268 
274  protected function ‪getPageTitle(): array
275  {
276  $pageTitle = [
277  'title' => ‪BackendUtility::getRecordTitle($this->table, $this->row)
278  ];
279  if ($this->type === 'folder') {
280  $pageTitle['title'] = htmlspecialchars($this->folderObject->getName());
281  $pageTitle['table'] = $this->‪getLanguageService()->‪sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:folder');
282  $pageTitle['icon'] = $this->iconFactory->getIconForResource($this->folderObject, ‪Icon::SIZE_SMALL)->render();
283  } elseif ($this->type === 'file') {
284  $pageTitle['table'] = $this->‪getLanguageService()->‪sL(‪$GLOBALS['TCA'][$this->table]['ctrl']['title']);
285  $pageTitle['icon'] = $this->iconFactory->getIconForResource($this->fileObject, ‪Icon::SIZE_SMALL)->render();
286  } else {
287  $pageTitle['table'] = $this->‪getLanguageService()->‪sL(‪$GLOBALS['TCA'][$this->table]['ctrl']['title']);
288  $pageTitle['icon'] = $this->iconFactory->getIconForRecord($this->table, $this->row, ‪Icon::SIZE_SMALL);
289  }
290  $this->moduleTemplate->setTitle($pageTitle['table'] . ': ' . $pageTitle['title']);
291  return $pageTitle;
292  }
293 
299  protected function ‪getPreview(): array
300  {
301  $preview = [];
302  // Perhaps @todo in future: Also display preview for records - without fileObject
303  if (!$this->fileObject) {
304  return $preview;
305  }
306 
307  // check if file is marked as missing
308  if ($this->fileObject->isMissing()) {
309  $preview['missingFile'] = $this->fileObject->getName();
310  } else {
311  ‪$rendererRegistry = GeneralUtility::makeInstance(RendererRegistry::class);
312  $fileRenderer = ‪$rendererRegistry->getRenderer($this->fileObject);
313  $preview['url'] = $this->fileObject->getPublicUrl(true);
314 
315  $width = min(590, $this->fileObject->getMetaData()['width'] ?? 590) . 'm';
316  $height = min(400, $this->fileObject->getMetaData()['height'] ?? 400) . 'm';
317 
318  // Check if there is a FileRenderer
319  if ($fileRenderer !== null) {
320  $preview['fileRenderer'] = $fileRenderer->render(
321  $this->fileObject,
322  $width,
323  $height,
324  [],
325  true
326  );
327 
328  // else check if we can create an Image preview
329  } elseif ($this->fileObject->isImage()) {
330  $preview['fileObject'] = ‪$this->fileObject;
331  $preview['width'] = $width;
332  $preview['height'] = $height;
333  }
334  }
335  return $preview;
336  }
337 
343  protected function ‪getPropertiesForTable(): array
344  {
345  $lang = $this->‪getLanguageService();
346  $propertiesForTable = [];
347  $propertiesForTable['extraFields'] = $this->‪getExtraFields();
348 
349  // Traverse the list of fields to display for the record:
350  $fieldList = $this->‪getFieldList($this->table, (int)$this->row['uid']);
351 
352  foreach ($fieldList as $name) {
353  $name = trim($name);
354  ‪$uid = $this->row['uid'];
355 
356  if (!isset(‪$GLOBALS['TCA'][$this->table]['columns'][$name])) {
357  continue;
358  }
359 
360  // not a real field -> skip
361  if ($this->type === 'file' && $name === 'fileinfo') {
362  continue;
363  }
364 
365  $isExcluded = !(!‪$GLOBALS['TCA'][‪$this->table]['columns'][$name]['exclude'] || $this->‪getBackendUser()->‪check('non_exclude_fields', $this->table . ':' . $name));
366  if ($isExcluded) {
367  continue;
368  }
369  $label = $lang->sL(‪BackendUtility::getItemLabel($this->table, $name));
370  $label = $label ?: $name;
371 
372  $propertiesForTable['fields'][] = [
373  'fieldValue' => ‪BackendUtility::getProcessedValue($this->table, $name, $this->row[$name], 0, false, false, ‪$uid),
374  'fieldLabel' => htmlspecialchars($label)
375  ];
376  }
377 
378  // additional information for folders and files
379  if ($this->folderObject instanceof Folder || $this->fileObject instanceof File) {
380  // storage
381  if ($this->folderObject instanceof Folder) {
382  $propertiesForTable['fields']['storage'] = [
383  'fieldValue' => $this->folderObject->getStorage()->getName(),
384  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_file.storage'))
385  ];
386  }
387 
388  // folder
389  $resourceObject = $this->fileObject ?: ‪$this->folderObject;
390  $propertiesForTable['fields']['folder'] = [
391  'fieldValue' => $resourceObject->getParentFolder()->getReadablePath(),
392  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:folder'))
393  ];
394 
395  if ($this->fileObject instanceof File) {
396  // show file dimensions for images
397  if ($this->fileObject->getType() === ‪AbstractFile::FILETYPE_IMAGE) {
398  $propertiesForTable['fields']['width'] = [
399  'fieldValue' => $this->fileObject->getProperty('width') . 'px',
400  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.width'))
401  ];
402  $propertiesForTable['fields']['height'] = [
403  'fieldValue' => $this->fileObject->getProperty('height') . 'px',
404  'fieldLabel' => htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.height'))
405  ];
406  }
407 
408  // file size
409  $propertiesForTable['fields']['size'] = [
410  'fieldValue' => GeneralUtility::formatSize((int)$this->fileObject->getProperty('size'), htmlspecialchars($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:byteSizeUnits'))),
411  'fieldLabel' => $lang->sL(‪BackendUtility::getItemLabel($this->table, 'size'))
412  ];
413 
414  // show the metadata of a file as well
415  ‪$table = 'sys_file_metadata';
416  $metaDataRepository = GeneralUtility::makeInstance(MetaDataRepository::class);
418  $metaData = $metaDataRepository->findByFileUid($this->row['uid']);
419  $allowedFields = $this->‪getFieldList(‪$table, (int)$metaData['uid']);
420 
421  foreach ($metaData as $name => $value) {
422  if (in_array($name, $allowedFields, true)) {
423  if (!isset(‪$GLOBALS['TCA'][‪$table]['columns'][$name])) {
424  continue;
425  }
426 
427  $isExcluded = !(!‪$GLOBALS['TCA'][‪$table]['columns'][$name]['exclude'] || $this->‪getBackendUser()->‪check('non_exclude_fields', ‪$table . ':' . $name));
428  if ($isExcluded) {
429  continue;
430  }
431 
432  $label = $lang->sL(‪BackendUtility::getItemLabel(‪$table, $name));
433  $label = $label ?: $name;
434 
435  $propertiesForTable['fields'][] = [
436  'fieldValue' => ‪BackendUtility::getProcessedValue(‪$table, $name, $metaData[$name], 0, false, false, (int)$metaData['uid']),
437  'fieldLabel' => htmlspecialchars($label)
438  ];
439  }
440  }
441  }
442  }
443 
444  return $propertiesForTable;
445  }
446 
454  protected function ‪getFieldList(string ‪$table, int ‪$uid): array
455  {
456  $formDataGroup = GeneralUtility::makeInstance(TcaDatabaseRecord::class);
457  $formDataCompiler = GeneralUtility::makeInstance(FormDataCompiler::class, $formDataGroup);
458  $formDataCompilerInput = [
459  'command' => 'edit',
460  'tableName' => ‪$table,
461  'vanillaUid' => ‪$uid,
462  ];
463  try {
464  $result = $formDataCompiler->compile($formDataCompilerInput);
465  $fieldList = array_unique(array_values($result['columnsToProcess']));
466 
467  $ctrlKeysOfUnneededFields = ['origUid', 'transOrigPointerField', 'transOrigDiffSourceField'];
468  foreach ($ctrlKeysOfUnneededFields as $field) {
469  if (($key = array_search(‪$GLOBALS['TCA'][‪$table]['ctrl'][$field], $fieldList, true)) !== false) {
470  unset($fieldList[$key]);
471  }
472  }
473  } catch (‪Exception $exception) {
474  $fieldList = [];
475  }
476 
477  $searchFields = ‪GeneralUtility::trimExplode(',', ‪$GLOBALS['TCA'][‪$table]['ctrl']['searchFields']);
478 
479  return array_unique(array_merge($fieldList, $searchFields));
480  }
481 
487  protected function ‪getExtraFields(): array
488  {
489  $lang = $this->‪getLanguageService();
490  $keyLabelPair = [];
491  if (in_array($this->type, ['folder', 'file'], true)) {
492  if ($this->type === 'file') {
493  $keyLabelPair['uid'] = [
494  'value' => ‪BackendUtility::getProcessedValueExtra($this->table, 'uid', $this->row['uid']),
495  'fieldLabel' => rtrim(htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:show_item.php.uid')), ':'),
496  ];
497  $keyLabelPair['creation_date'] = [
498  'value' => ‪BackendUtility::datetime($this->row['creation_date']),
499  'fieldLabel' => rtrim(htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.creationDate')), ':'),
500  'isDatetime' => true,
501  ];
502  $keyLabelPair['modification_date'] = [
503  'value' => ‪BackendUtility::datetime($this->row['modification_date']),
504  'fieldLabel' => rtrim(htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.timestamp')), ':'),
505  'isDatetime' => true,
506  ];
507  }
508  } else {
509  $keyLabelPair['uid'] = [
510  'value' => ‪BackendUtility::getProcessedValueExtra($this->table, 'uid', $this->row['uid']),
511  'fieldLabel' => rtrim(htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:show_item.php.uid')), ':'),
512  ];
513  foreach (['crdate' => 'creationDate', 'tstamp' => 'timestamp', 'cruser_id' => 'creationUserId'] as $field => $label) {
514  if (isset(‪$GLOBALS['TCA'][$this->table]['ctrl'][$field])) {
515  if ($field === 'crdate' || $field === 'tstamp') {
516  $keyLabelPair[$field] = [
517  'value' => ‪BackendUtility::datetime($this->row[‪$GLOBALS['TCA'][$this->table]['ctrl'][$field]]),
518  'fieldLabel' => rtrim(htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.' . $label)), ':'),
519  'isDatetime' => true,
520  ];
521  }
522  if ($field === 'cruser_id') {
523  $rowValue = ‪BackendUtility::getProcessedValueExtra($this->table, ‪$GLOBALS['TCA'][$this->table]['ctrl'][$field], $this->row[‪$GLOBALS['TCA'][$this->table]['ctrl'][$field]]);
524  if ($rowValue) {
525  $creatorRecord = ‪BackendUtility::getRecord('be_users', (int)$rowValue);
526  if ($creatorRecord) {
528  $avatar = GeneralUtility::makeInstance(Avatar::class);
529  $creatorRecord['icon'] = $avatar->render($creatorRecord);
530  $rowValue = $creatorRecord;
531  $keyLabelPair['creatorRecord'] = [
532  'value' => $rowValue,
533  'fieldLabel' => rtrim(htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.' . $label)), ':'),
534  ];
535  }
536  }
537  }
538  }
539  }
540  }
541  return $keyLabelPair;
542  }
543 
550  protected function ‪getReferences(ServerRequestInterface $request): array
551  {
552  $references = [];
553  switch ($this->type) {
554  case 'db': {
555  $references['refLines'] = $this->‪makeRef($this->table, $this->uid, $request);
556  $references['refFromLines'] = $this->‪makeRefFrom($this->table, $this->uid, $request);
557  break;
558  }
559 
560  case 'file': {
561  if ($this->fileObject && $this->fileObject->isIndexed()) {
562  $references['refLines'] = $this->‪makeRef('_FILE', $this->fileObject, $request);
563  }
564  break;
565  }
566  }
567  return $references;
568  }
569 
577  protected function ‪getLabelForTableColumn($tableName, $fieldName): string
578  {
579  if (‪$GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label'] !== null) {
580  $field = $this->‪getLanguageService()->‪sL(‪$GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label']);
581  if (trim($field) === '') {
582  $field = $fieldName;
583  }
584  } else {
585  $field = $fieldName;
586  }
587  return $field;
588  }
589 
599  protected function ‪getRecordActions(‪$table, ‪$uid, ServerRequestInterface $request): array
600  {
601  if (‪$table === '' || ‪$uid < 0) {
602  return [];
603  }
604 
605  $actions = [];
606  // Edit button
607  $urlParameters = [
608  'edit' => [
609  ‪$table => [
610  ‪$uid => 'edit'
611  ]
612  ],
613  'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri()
614  ];
615  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
616  $actions['recordEditUrl'] = (string)$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)$uriBuilder->buildUriFromRoute('record_history', $urlParameters);
624 
625  if (‪$table === 'pages') {
626  // Recordlist button
627  $actions['webListUrl'] = (string)$uriBuilder->buildUriFromRoute('web_list', ['id' => ‪$uid, 'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri()]);
628 
629  // View page button
631  }
632 
633  return $actions;
634  }
635 
645  protected function ‪makeRef(‪$table, $ref, ServerRequestInterface $request): array
646  {
647  $refLines = [];
648  $lang = $this->‪getLanguageService();
649  // Files reside in sys_file table
650  if ($table === '_FILE') {
651  $selectTable = 'sys_file';
652  $selectUid = $ref->getUid();
653  } else {
654  $selectTable = ‪$table;
655  $selectUid = $ref;
656  }
657  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
658  ->getQueryBuilderForTable('sys_refindex');
659 
660  $predicates = [
661  $queryBuilder->expr()->eq(
662  'ref_table',
663  $queryBuilder->createNamedParameter($selectTable, \PDO::PARAM_STR)
664  ),
665  $queryBuilder->expr()->eq(
666  'ref_uid',
667  $queryBuilder->createNamedParameter($selectUid, \PDO::PARAM_INT)
668  ),
669  $queryBuilder->expr()->eq(
670  'deleted',
671  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
672  )
673  ];
674 
675  $backendUser = $this->‪getBackendUser();
676  if (!$backendUser->isAdmin()) {
677  $allowedSelectTables = ‪GeneralUtility::trimExplode(',', $backendUser->groupData['tables_select']);
678  $predicates[] = $queryBuilder->expr()->in(
679  'tablename',
680  $queryBuilder->createNamedParameter($allowedSelectTables, Connection::PARAM_STR_ARRAY)
681  );
682  }
683 
684  $rows = $queryBuilder
685  ->select('*')
686  ->from('sys_refindex')
687  ->where(...$predicates)
688  ->execute()
689  ->fetchAll();
690 
691  // Compile information for title tag:
692  foreach ($rows as ‪$row) {
693  if (‪$row['tablename'] === 'sys_file_reference') {
695  if (‪$row['tablename'] === null || ‪$row['recuid'] === null) {
696  return [];
697  }
698  }
699 
700  $line = [];
701  $record = ‪BackendUtility::getRecord(‪$row['tablename'], ‪$row['recuid']);
702  if ($record) {
703  ‪BackendUtility::fixVersioningPid(‪$row['tablename'], $record);
704  if (!$this->‪canAccessPage($row['tablename'], $record)) {
705  continue;
706  }
707  $parentRecord = ‪BackendUtility::getRecord('pages', $record['pid']);
708  $parentRecordTitle = is_array($parentRecord)
709  ? ‪BackendUtility::getRecordTitle('pages', $parentRecord)
710  : '';
711  $urlParameters = [
712  'edit' => [
713  ‪$row['tablename'] => [
714  ‪$row['recuid'] => 'edit'
715  ]
716  ],
717  'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri()
718  ];
719  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
720  $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
721  $line['url'] = $url;
722  $line['icon'] = $this->iconFactory->getIconForRecord(‪$row['tablename'], $record, ‪Icon::SIZE_SMALL)->render();
723  $line['row'] = ‪$row;
724  $line['record'] = $record;
725  $line['recordTitle'] = ‪BackendUtility::getRecordTitle(‪$row['tablename'], $record, false, true);
726  $line['parentRecordTitle'] = $parentRecordTitle;
727  $line['title'] = $lang->sL(‪$GLOBALS['TCA'][‪$row['tablename']]['ctrl']['title']);
728  $line['labelForTableColumn'] = $this->‪getLabelForTableColumn($row['tablename'], ‪$row['field']);
729  $line['path'] = ‪BackendUtility::getRecordPath($record['pid'], '', 0, 0);
730  $line['actions'] = $this->‪getRecordActions($row['tablename'], ‪$row['recuid'], $request);
731  } else {
732  $line['row'] = ‪$row;
733  $line['title'] = $lang->sL(‪$GLOBALS['TCA'][‪$row['tablename']]['ctrl']['title']) ?: ‪$row['tablename'];
734  $line['labelForTableColumn'] = $this->‪getLabelForTableColumn($row['tablename'], ‪$row['field']);
735  }
736  $refLines[] = $line;
737  }
738  return $refLines;
739  }
740 
749  protected function ‪makeRefFrom(‪$table, $ref, ServerRequestInterface $request): array
750  {
751  $refFromLines = [];
752  $lang = $this->‪getLanguageService();
753 
754  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
755  ->getQueryBuilderForTable('sys_refindex');
756 
757  $predicates = [
758  $queryBuilder->expr()->eq(
759  'tablename',
760  $queryBuilder->createNamedParameter(‪$table, \PDO::PARAM_STR)
761  ),
762  $queryBuilder->expr()->eq(
763  'recuid',
764  $queryBuilder->createNamedParameter($ref, \PDO::PARAM_INT)
765  )
766  ];
767 
768  $backendUser = $this->‪getBackendUser();
769  if (!$backendUser->isAdmin()) {
770  $allowedSelectTables = ‪GeneralUtility::trimExplode(',', $backendUser->groupData['tables_select']);
771  $predicates[] = $queryBuilder->expr()->in(
772  'ref_table',
773  $queryBuilder->createNamedParameter($allowedSelectTables, Connection::PARAM_STR_ARRAY)
774  );
775  }
776 
777  $rows = $queryBuilder
778  ->select('*')
779  ->from('sys_refindex')
780  ->where(...$predicates)
781  ->execute()
782  ->fetchAll();
783 
784  // Compile information for title tag:
785  foreach ($rows as ‪$row) {
786  $line = [];
787  $record = ‪BackendUtility::getRecord(‪$row['ref_table'], ‪$row['ref_uid']);
788  if ($record) {
789  ‪BackendUtility::fixVersioningPid(‪$row['ref_table'], $record);
790  if (!$this->‪canAccessPage($row['ref_table'], $record)) {
791  continue;
792  }
793  $urlParameters = [
794  'edit' => [
795  ‪$row['ref_table'] => [
796  ‪$row['ref_uid'] => 'edit'
797  ]
798  ],
799  'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri()
800  ];
801  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
802  $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
803  $line['url'] = $url;
804  $line['icon'] = $this->iconFactory->getIconForRecord(‪$row['tablename'], $record, ‪Icon::SIZE_SMALL)->render();
805  $line['row'] = ‪$row;
806  $line['record'] = $record;
807  $line['recordTitle'] = ‪BackendUtility::getRecordTitle(‪$row['ref_table'], $record, false, true);
808  $line['title'] = $lang->sL(‪$GLOBALS['TCA'][‪$row['ref_table']]['ctrl']['title']);
809  $line['labelForTableColumn'] = $this->‪getLabelForTableColumn($table, ‪$row['field']);
810  $line['path'] = ‪BackendUtility::getRecordPath($record['pid'], '', 0, 0);
811  $line['actions'] = $this->‪getRecordActions($row['ref_table'], ‪$row['ref_uid'], $request);
812  } else {
813  $line['row'] = ‪$row;
814  $line['title'] = $lang->sL(‪$GLOBALS['TCA'][‪$row['ref_table']]['ctrl']['title']);
815  $line['labelForTableColumn'] = $this->‪getLabelForTableColumn($table, ‪$row['field']);
816  }
817  $refFromLines[] = $line;
818  }
819  return $refFromLines;
820  }
821 
828  protected function ‪transformFileReferenceToRecordReference(array $referenceRecord): array
829  {
830  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
831  ->getQueryBuilderForTable('sys_file_reference');
832  $queryBuilder->getRestrictions()->removeAll();
833  $fileReference = $queryBuilder
834  ->select('*')
835  ->from('sys_file_reference')
836  ->where(
837  $queryBuilder->expr()->eq(
838  'uid',
839  $queryBuilder->createNamedParameter($referenceRecord['recuid'], \PDO::PARAM_INT)
840  )
841  )
842  ->execute()
843  ->fetch();
844 
845  return [
846  'recuid' => $fileReference['uid_foreign'],
847  'tablename' => $fileReference['tablenames'],
848  'field' => $fileReference['fieldname'],
849  'flexpointer' => '',
850  'softref_key' => '',
851  'sorting' => $fileReference['sorting_foreign']
852  ];
853  }
854 
860  protected function ‪canAccessPage(string $tableName, array $record): bool
861  {
862  $recordPid = (int)($tableName === 'pages' ? $record['uid'] : $record['pid']);
863  return $this->‪getBackendUser()->‪isInWebMount($tableName === 'pages' ? $record : $record['pid'])
864  || $recordPid === 0 && !empty(‪$GLOBALS['TCA'][$tableName]['ctrl']['security']['ignoreRootLevelRestriction']);
865  }
866 
870  protected function ‪getLanguageService(): ‪LanguageService
871  {
872  return ‪$GLOBALS['LANG'];
873  }
874 
878  protected function ‪getBackendUser(): ‪BackendUserAuthentication
879  {
880  return ‪$GLOBALS['BE_USER'];
881  }
882 }
‪TYPO3\CMS\Core\Resource\Index\MetaDataRepository
Definition: MetaDataRepository.php:40
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: ElementInformationController.php:83
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getPropertiesForTable
‪array getPropertiesForTable()
Definition: ElementInformationController.php:332
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$permsClause
‪string $permsClause
Definition: ElementInformationController.php:67
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getExtraFields
‪array getExtraFields()
Definition: ElementInformationController.php:476
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getPagePermsClause
‪string getPagePermsClause($perms)
Definition: BackendUserAuthentication.php:499
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: ElementInformationController.php:125
‪TYPO3\CMS\Backend\Utility\BackendUtility\datetime
‪static string datetime($value)
Definition: BackendUtility.php:989
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$row
‪array $row
Definition: ElementInformationController.php:96
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getPreview
‪array getPreview()
Definition: ElementInformationController.php:288
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getPageTitle
‪array getPageTitle()
Definition: ElementInformationController.php:263
‪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:634
‪TYPO3\CMS\Backend\Exception
Definition: Exception.php:24
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\transformFileReferenceToRecordReference
‪array transformFileReferenceToRecordReference(array $referenceRecord)
Definition: ElementInformationController.php:817
‪TYPO3\CMS\Backend\Controller\ContentElement
Definition: ElementHistoryController.php:16
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\check
‪bool check($type, $value)
Definition: BackendUserAuthentication.php:624
‪TYPO3\CMS\Backend\Utility\BackendUtility\getItemLabel
‪static string getItemLabel($table, $col)
Definition: BackendUtility.php:1521
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController
Definition: ElementInformationController.php:52
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getFieldList
‪array getFieldList(string $table, int $uid)
Definition: ElementInformationController.php:443
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:194
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getLabelForTableColumn
‪string getLabelForTableColumn($tableName, $fieldName)
Definition: ElementInformationController.php:566
‪TYPO3\CMS\Backend\Utility\BackendUtility\BEgetRootLine
‪static array BEgetRootLine($uid, $clause='', $workspaceOL=false, array $additionalFields=[])
Definition: BackendUtility.php:343
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\canAccessPage
‪bool canAccessPage(string $tableName, array $record)
Definition: ElementInformationController.php:849
‪TYPO3\CMS\Core\Resource\AbstractFile\FILETYPE_IMAGE
‪const FILETYPE_IMAGE
Definition: AbstractFile.php:78
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:43
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\main
‪main(ServerRequestInterface $request)
Definition: ElementInformationController.php:215
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$table
‪string $table
Definition: ElementInformationController.php:57
‪TYPO3\CMS\Backend\Utility\BackendUtility\fixVersioningPid
‪static fixVersioningPid($table, &$rr, $ignoreWorkspaceMatch=false)
Definition: BackendUtility.php:3511
‪TYPO3\CMS\Core\Resource\AbstractFile
Definition: AbstractFile.php:26
‪TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
Definition: RouteNotFoundException.php:22
‪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:38
‪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\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1541
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\initFileOrFolderRecord
‪initFileOrFolderRecord()
Definition: ElementInformationController.php:187
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: ElementInformationController.php:867
‪TYPO3\CMS\Backend\Utility\BackendUtility\getProcessedValueExtra
‪static string getProcessedValueExtra( $table, $fN, $fV, $fixed_lgd_chars=0, $uid=0, $forceResult=true, $pid=0)
Definition: BackendUtility.php:2100
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:33
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\init
‪init(ServerRequestInterface $request)
Definition: ElementInformationController.php:138
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$type
‪string $type
Definition: ElementInformationController.php:79
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:139
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$iconFactory
‪IconFactory $iconFactory
Definition: ElementInformationController.php:108
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Backend\Utility\BackendUtility\readPageAccess
‪static array false readPageAccess($id, $perms_clause)
Definition: BackendUtility.php:597
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\initDatabaseRecord
‪initDatabaseRecord()
Definition: ElementInformationController.php:159
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$access
‪bool $access
Definition: ElementInformationController.php:71
‪TYPO3\CMS\Backend\Utility\BackendUtility\viewOnClick
‪static string viewOnClick( $pageUid, $backPath='', $rootLine=null, $anchorSection='', $alternativeUrl='', $additionalGetVars='', $switchFocus=true)
Definition: BackendUtility.php:2359
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\__construct
‪__construct()
Definition: ElementInformationController.php:113
‪TYPO3\CMS\Backend\Utility\BackendUtility\getProcessedValue
‪static string null getProcessedValue( $table, $col, $value, $fixed_lgd_chars=0, $defaultPassthrough=false, $noRecordLookup=false, $uid=0, $forceResult=true, $pid=0)
Definition: BackendUtility.php:1664
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getReferences
‪array getReferences(ServerRequestInterface $request)
Definition: ElementInformationController.php:539
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$uid
‪int $uid
Definition: ElementInformationController.php:63
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$fileObject
‪TYPO3 CMS Core Resource File null $fileObject
Definition: ElementInformationController.php:100
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\$folderObject
‪Folder $folderObject
Definition: ElementInformationController.php:104
‪TYPO3\CMS\Backend\Controller\ContentElement\ElementInformationController\getLanguageService
‪LanguageService getLanguageService()
Definition: ElementInformationController.php:859
‪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:588
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordPath
‪static mixed getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit=0)
Definition: BackendUtility.php:546
‪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:90
‪$rendererRegistry
‪$rendererRegistry
Definition: ext_localconf.php:19
‪TYPO3\CMS\Core\Resource\Rendering\RendererRegistry
Definition: RendererRegistry.php:26
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isInWebMount
‪int null isInWebMount($idOrRow, $readPerms='', $exitOnError=0)
Definition: BackendUserAuthentication.php:352