[CLEANUP] Use Permission constants consistently
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / ContentElement / ElementInformationController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\ContentElement;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Backend\Avatar\Avatar;
20 use TYPO3\CMS\Backend\Template\ModuleTemplate;
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
22 use TYPO3\CMS\Core\Database\ConnectionPool;
23 use TYPO3\CMS\Core\Imaging\Icon;
24 use TYPO3\CMS\Core\Imaging\IconFactory;
25 use TYPO3\CMS\Core\Resource\AbstractFile;
26 use TYPO3\CMS\Core\Resource\Folder;
27 use TYPO3\CMS\Core\Resource\ResourceFactory;
28 use TYPO3\CMS\Core\Type\Bitmask\Permission;
29 use TYPO3\CMS\Core\Utility\GeneralUtility;
30 use TYPO3\CMS\Fluid\View\StandaloneView;
31
32 /**
33 * Script Class for showing information about an item.
34 */
35 class ElementInformationController
36 {
37 /**
38 * Record table name
39 *
40 * @var string
41 */
42 public $table;
43
44 /**
45 * Record uid
46 *
47 * @var int
48 */
49 public $uid;
50
51 /**
52 * @var string
53 */
54 protected $permsClause;
55
56 /**
57 * @var bool
58 */
59 public $access = false;
60
61 /**
62 * Which type of element:
63 * - "file"
64 * - "db"
65 *
66 * @var string
67 */
68 public $type = '';
69
70 /**
71 * @var ModuleTemplate
72 */
73 protected $moduleTemplate;
74
75 /**
76 * For type "db": Set to page record of the parent page of the item set
77 * (if type="db")
78 *
79 * @var array
80 */
81 public $pageInfo;
82
83 /**
84 * Database records identified by table/uid
85 *
86 * @var array
87 */
88 protected $row;
89
90 /**
91 * @var \TYPO3\CMS\Core\Resource\File
92 */
93 protected $fileObject;
94
95 /**
96 * @var Folder
97 */
98 protected $folderObject;
99
100 /**
101 * @var IconFactory
102 */
103 protected $iconFactory;
104
105 /**
106 * Constructor
107 */
108 public function __construct()
109 {
110 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
111 $GLOBALS['SOBE'] = $this;
112
113 $this->init();
114 }
115
116 /**
117 * Determines if table/uid point to database record or file and
118 * if user has access to view information
119 */
120 public function init()
121 {
122 $this->table = GeneralUtility::_GET('table');
123 $this->uid = GeneralUtility::_GET('uid');
124
125 $this->permsClause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW);
126 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
127 $this->moduleTemplate->getDocHeaderComponent()->disable();
128
129 if (isset($GLOBALS['TCA'][$this->table])) {
130 $this->initDatabaseRecord();
131 } elseif ($this->table === '_FILE' || $this->table === '_FOLDER' || $this->table === 'sys_file') {
132 $this->initFileOrFolderRecord();
133 }
134 }
135
136 /**
137 * Init database records (table)
138 */
139 protected function initDatabaseRecord()
140 {
141 $this->type = 'db';
142 $this->uid = (int)$this->uid;
143
144 // Check permissions and uid value:
145 if ($this->uid && $this->getBackendUser()->check('tables_select', $this->table)) {
146 if ((string)$this->table === 'pages') {
147 $this->pageInfo = BackendUtility::readPageAccess($this->uid, $this->permsClause);
148 $this->access = is_array($this->pageInfo);
149 $this->row = $this->pageInfo;
150 } else {
151 $this->row = BackendUtility::getRecordWSOL($this->table, $this->uid);
152 if ($this->row) {
153 $this->pageInfo = BackendUtility::readPageAccess($this->row['pid'], $this->permsClause);
154 $this->access = is_array($this->pageInfo);
155 }
156 }
157 }
158 }
159
160 /**
161 * Init file/folder parameters
162 */
163 protected function initFileOrFolderRecord()
164 {
165 $fileOrFolderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->uid);
166
167 if ($fileOrFolderObject instanceof Folder) {
168 $this->folderObject = $fileOrFolderObject;
169 $this->access = $this->folderObject->checkActionPermission('read');
170 $this->type = 'folder';
171 } else {
172 $this->fileObject = $fileOrFolderObject;
173 $this->access = $this->fileObject->checkActionPermission('read');
174 $this->type = 'file';
175 $this->table = 'sys_file';
176
177 try {
178 $this->row = BackendUtility::getRecordWSOL($this->table, $fileOrFolderObject->getUid());
179 } catch (\Exception $e) {
180 $this->row = [];
181 }
182 }
183 }
184
185 /**
186 * Injects the request object for the current request or subrequest
187 * As this controller goes only through the main() method, it is rather simple for now
188 *
189 * @param ServerRequestInterface $request the current request
190 * @param ResponseInterface $response
191 * @return ResponseInterface the response with the content
192 */
193 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
194 {
195 $this->main();
196
197 $response->getBody()->write($this->moduleTemplate->renderContent());
198 return $response;
199 }
200
201 /**
202 * Compiles the whole content to be outputted, which is then set as content to the moduleTemplate
203 * There is a hook to do a custom rendering of a record.
204 */
205 public function main()
206 {
207 $content = '';
208
209 // Rendering of the output via fluid
210 $view = GeneralUtility::makeInstance(StandaloneView::class);
211 $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
212 $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
213 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
214 'EXT:backend/Resources/Private/Templates/ContentElement/ElementInformation.html'
215 ));
216
217 if ($this->access) {
218 // render type by user func
219 $typeRendered = false;
220 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] ?? [] as $className) {
221 $typeRenderObj = GeneralUtility::makeInstance($className);
222 if (is_object($typeRenderObj) && method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render')) {
223 if ($typeRenderObj->isValid($this->type, $this)) {
224 $content .= $typeRenderObj->render($this->type, $this);
225 $typeRendered = true;
226 break;
227 }
228 }
229 }
230
231 if (!$typeRendered) {
232 $view->assign('accessAllowed', true);
233 $view->assignMultiple($this->getPageTitle());
234 $view->assignMultiple($this->getPreview());
235 $view->assignMultiple($this->getPropertiesForTable());
236 $view->assignMultiple($this->getReferences());
237 $view->assignMultiple($this->getBackButton());
238 $view->assign('maxTitleLength', $this->getBackendUser()->uc['titleLen'] ?? 20);
239 $content .= $view->render();
240 }
241 } else {
242 $content .= $view->render();
243 }
244
245 $this->moduleTemplate->setContent($content);
246 }
247
248 /**
249 * Get page title with icon, table title and record title
250 *
251 * @return array
252 */
253 protected function getPageTitle() : array
254 {
255 $pageTitle = [
256 'title' => BackendUtility::getRecordTitle($this->table, $this->row, false)
257 ];
258 if ($this->type === 'folder') {
259 $pageTitle['table'] = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:folder');
260 $pageTitle['icon'] = $this->iconFactory->getIconForResource($this->folderObject, Icon::SIZE_SMALL)->render();
261 } elseif ($this->type === 'file') {
262 $pageTitle['table'] = $this->getLanguageService()->sL($GLOBALS['TCA'][$this->table]['ctrl']['title']);
263 $pageTitle['icon'] = $this->iconFactory->getIconForResource($this->fileObject, Icon::SIZE_SMALL)->render();
264 } else {
265 $pageTitle['table'] = $this->getLanguageService()->sL($GLOBALS['TCA'][$this->table]['ctrl']['title']);
266 $pageTitle['icon'] = $this->iconFactory->getIconForRecord($this->table, $this->row, Icon::SIZE_SMALL);
267 }
268 $this->moduleTemplate->setTitle($pageTitle['table'] . ': ' . $pageTitle['title']);
269 return $pageTitle;
270 }
271
272 /**
273 * Get preview for current record
274 *
275 * @return array
276 */
277 protected function getPreview() : array
278 {
279 $preview = [];
280 // Perhaps @todo in future: Also display preview for records - without fileObject
281 if (!$this->fileObject) {
282 return $preview;
283 }
284
285 // check if file is marked as missing
286 if ($this->fileObject->isMissing()) {
287 $preview['missingFile'] =$this->fileObject->getName();
288 } else {
289 /** @var \TYPO3\CMS\Core\Resource\Rendering\RendererRegistry $rendererRegistry */
290 $rendererRegistry = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Rendering\RendererRegistry::class);
291 $fileRenderer = $rendererRegistry->getRenderer($this->fileObject);
292 $fileExtension = $this->fileObject->getExtension();
293 $preview['url'] = $this->fileObject->getPublicUrl(true);
294
295 $width = '590m';
296 $heigth = '400m';
297
298 // Check if there is a FileRenderer
299 if ($fileRenderer !== null) {
300 $preview['fileRenderer'] = $fileRenderer->render(
301 $this->fileObject,
302 $width,
303 $heigth,
304 [],
305 true
306 );
307
308 // else check if we can create an Image preview
309 } elseif (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
310 $preview['fileObject'] = $this->fileObject;
311 $preview['width'] = $width;
312 $preview['heigth'] = $heigth;
313 }
314 }
315 return $preview;
316 }
317
318 /**
319 * Get property array for html table
320 *
321 * @return array
322 */
323 protected function getPropertiesForTable() : array
324 {
325 $propertiesForTable = [];
326 $lang = $this->getLanguageService();
327
328 $extraFields = [
329 'uid' => htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.uid'))
330 ];
331
332 if (in_array($this->type, ['folder', 'file'], true)) {
333 if ($this->type === 'file') {
334 $extraFields['creation_date'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.creationDate'));
335 $extraFields['modification_date'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.timestamp'));
336 if ($this->fileObject->getType() === AbstractFile::FILETYPE_IMAGE) {
337 $extraFields['width'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.width'));
338 $extraFields['height'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.height'));
339 }
340 }
341 $extraFields['storage'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file.storage'));
342 $extraFields['folder'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:folder'));
343 } else {
344 $extraFields['crdate'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.creationDate'));
345 $extraFields['cruser_id'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.creationUserId'));
346 $extraFields['tstamp'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.timestamp'));
347
348 // check if the special fields are defined in the TCA ctrl section of the table
349 foreach ($extraFields as $fieldName => $fieldLabel) {
350 if (isset($GLOBALS['TCA'][$this->table]['ctrl'][$fieldName])) {
351 $extraFields[$GLOBALS['TCA'][$this->table]['ctrl'][$fieldName]] = $fieldLabel;
352 } elseif ($fieldName !== 'uid') {
353 unset($extraFields[$fieldName]);
354 }
355 }
356 }
357
358 foreach ($extraFields as $name => $fieldLabel) {
359 $rowValue = '';
360 $thisRow = [];
361 if (!isset($this->row[$name])) {
362 $resourceObject = $this->fileObject ?: $this->folderObject;
363 if ($name === 'storage') {
364 $rowValue = $resourceObject->getStorage()->getName();
365 } elseif ($name === 'folder') {
366 $rowValue = $resourceObject->getParentFolder()->getReadablePath();
367 } elseif ($name === 'width') {
368 $rowValue = $this->fileObject->getProperty('width') . 'px';
369 } elseif ($name === 'height') {
370 $rowValue = $this->fileObject->getProperty('height') . 'px';
371 }
372 } elseif ($name === 'creation_date' || $name === 'modification_date') {
373 $rowValue = BackendUtility::datetime($this->row[$name]);
374 } else {
375 $rowValue = BackendUtility::getProcessedValueExtra($this->table, $name, $this->row[$name]);
376 }
377 $thisRow['value'] = $rowValue;
378 $thisRow['fieldLabel'] = rtrim($fieldLabel, ':');
379 // show the backend username who created the issue
380 if ($name === 'cruser_id' && $rowValue) {
381 $creatorRecord = BackendUtility::getRecord('be_users', $rowValue);
382 if ($creatorRecord) {
383 /** @var Avatar $avatar */
384 $avatar = GeneralUtility::makeInstance(Avatar::class);
385 $creatorRecord['icon'] = $avatar->render($creatorRecord);
386 $thisRow['creatorRecord'] = $creatorRecord;
387 $thisRow['value'] = '';
388 }
389 }
390 $propertiesForTable['extraFields'][] = $thisRow;
391 }
392
393 // Traverse the list of fields to display for the record:
394 $fieldList = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$this->table]['interface']['showRecordFieldList'], true);
395 foreach ($fieldList as $name) {
396 $thisRow = [];
397 $name = trim($name);
398 $uid = $this->row['uid'];
399
400 if (!isset($GLOBALS['TCA'][$this->table]['columns'][$name])) {
401 continue;
402 }
403
404 // Storage is already handled above
405 if ($this->type === 'file' && $name === 'storage') {
406 continue;
407 }
408
409 // format file size as bytes/kilobytes/megabytes
410 if ($this->type === 'file' && $name === 'size') {
411 $this->row[$name] = GeneralUtility::formatSize($this->row[$name], htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:byteSizeUnits')));
412 }
413
414 $isExcluded = !(!$GLOBALS['TCA'][$this->table]['columns'][$name]['exclude'] || $this->getBackendUser()->check('non_exclude_fields', $this->table . ':' . $name));
415 if ($isExcluded) {
416 continue;
417 }
418
419 $thisRow['fieldValue'] = BackendUtility::getProcessedValue($this->table, $name, $this->row[$name], 0, 0, false, $uid);
420 $thisRow['fieldLabel'] = htmlspecialchars($lang->sL(BackendUtility::getItemLabel($this->table, $name)));
421 $propertiesForTable['fields'][] = $thisRow;
422 }
423 return $propertiesForTable;
424 }
425
426 /**
427 * Get references section (references from and references to current record)
428 *
429 * @return array
430 */
431 protected function getReferences() : array
432 {
433 $references = [];
434 switch ($this->type) {
435 case 'db': {
436 $references['refLines'] = $this->makeRef($this->table, $this->row['uid']);
437 $references['refFromLines'] = $this->makeRefFrom($this->table, $this->row['uid']);
438 break;
439 }
440
441 case 'file': {
442 if ($this->fileObject && $this->fileObject->isIndexed()) {
443 $references['refLines'] = $this->makeRef('_FILE', $this->fileObject);
444 }
445 break;
446 }
447 }
448 return $references;
449 }
450
451 /**
452 * Get a back button, if a returnUrl was provided
453 *
454 * @return array
455 */
456 protected function getBackButton() : array
457 {
458 return ['returnUrl' => GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GET('returnUrl'))];
459 }
460
461 /**
462 * Get field name for specified table/column name
463 *
464 * @param string $tableName Table name
465 * @param string $fieldName Column name
466 * @return string label
467 */
468 public function getLabelForTableColumn($tableName, $fieldName)
469 {
470 if ($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label'] !== null) {
471 $field = $this->getLanguageService()->sL($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label']);
472 if (trim($field) === '') {
473 $field = $fieldName;
474 }
475 } else {
476 $field = $fieldName;
477 }
478 return $field;
479 }
480
481 /**
482 * Returns the record actions
483 *
484 * @param string $table
485 * @param int $uid
486 * @return array
487 */
488 protected function getRecordActions($table, $uid)
489 {
490 if ($table === '' || $uid < 0) {
491 return [];
492 }
493
494 $actions = [];
495 // Edit button
496 $urlParameters = [
497 'edit' => [
498 $table => [
499 $uid => 'edit'
500 ]
501 ],
502 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
503 ];
504 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
505 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
506 $actions['recordEditUrl'] = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
507
508 // History button
509 $urlParameters = [
510 'element' => $table . ':' . $uid,
511 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
512 ];
513 $actions['recordHistoryUrl'] = (string)$uriBuilder->buildUriFromRoute('record_history', $urlParameters);
514
515 if ($table === 'pages') {
516 // Recordlist button
517 $actions['webListUrl'] = (string)$uriBuilder->buildUriFromRoute('web_list', ['id' => $uid, 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')]);
518
519 // View page button
520 $actions['viewOnClick'] = BackendUtility::viewOnClick($uid, '', BackendUtility::BEgetRootLine($uid));
521 }
522
523 return $actions;
524 }
525
526 /**
527 * Make reference display
528 *
529 * @param string $table Table name
530 * @param string|\TYPO3\CMS\Core\Resource\File $ref Filename or uid
531 * @return array
532 */
533 protected function makeRef($table, $ref)
534 {
535 $refLines = [];
536 $lang = $this->getLanguageService();
537 // Files reside in sys_file table
538 if ($table === '_FILE') {
539 $selectTable = 'sys_file';
540 $selectUid = $ref->getUid();
541 } else {
542 $selectTable = $table;
543 $selectUid = $ref;
544 }
545 /** @var $queryBuilder \TYPO3\CMS\Core\Database\Query\QueryBuilder */
546 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
547 ->getQueryBuilderForTable('sys_refindex');
548 $rows = $queryBuilder
549 ->select('*')
550 ->from('sys_refindex')
551 ->where(
552 $queryBuilder->expr()->eq(
553 'ref_table',
554 $queryBuilder->createNamedParameter($selectTable, \PDO::PARAM_STR)
555 ),
556 $queryBuilder->expr()->eq(
557 'ref_uid',
558 $queryBuilder->createNamedParameter($selectUid, \PDO::PARAM_INT)
559 ),
560 $queryBuilder->expr()->eq(
561 'deleted',
562 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
563 )
564 )
565 ->execute()
566 ->fetchAll();
567
568 // Compile information for title tag:
569 foreach ($rows as $row) {
570 if ($row['tablename'] === 'sys_file_reference') {
571 $row = $this->transformFileReferenceToRecordReference($row);
572 if ($row['tablename'] === null || $row['recuid'] === null) {
573 return;
574 }
575 }
576 $line = [];
577 $record = BackendUtility::getRecord($row['tablename'], $row['recuid']);
578 if ($record) {
579 $parentRecord = BackendUtility::getRecord('pages', $record['pid']);
580 $parentRecordTitle = is_array($parentRecord)
581 ? BackendUtility::getRecordTitle('pages', $parentRecord)
582 : '';
583 $urlParameters = [
584 'edit' => [
585 $row['tablename'] => [
586 $row['recuid'] => 'edit'
587 ]
588 ],
589 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
590 ];
591 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
592 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
593 $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
594 $line['url'] = $url;
595 $line['icon'] = $this->iconFactory->getIconForRecord($row['tablename'], $record, Icon::SIZE_SMALL)->render();
596 $line['row'] = $row;
597 $line['record'] = $record;
598 $line['recordTitle'] = BackendUtility::getRecordTitle($row['tablename'], $record, false, true);
599 $line['parentRecordTitle'] = $parentRecordTitle;
600 $line['title'] = $lang->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title']);
601 $line['labelForTableColumn'] = $this->getLabelForTableColumn($row['tablename'], $row['field']);
602 $line['actions'] = $this->getRecordActions($row['tablename'], $row['recuid']);
603 } else {
604 $line['row'] = $row;
605 $line['title'] = $lang->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title']) ?: $row['tablename'];
606 $line['labelForTableColumn'] = $this->getLabelForTableColumn($row['tablename'], $row['field']);
607 }
608 $refLines[] = $line;
609 }
610 return $refLines;
611 }
612
613 /**
614 * Make reference display (what this elements points to)
615 *
616 * @param string $table Table name
617 * @param string $ref Filename or uid
618 * @return array
619 */
620 protected function makeRefFrom($table, $ref) : array
621 {
622 $refFromLines = [];
623 $lang = $this->getLanguageService();
624
625 /** @var $queryBuilder \TYPO3\CMS\Core\Database\Query\QueryBuilder */
626 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
627 ->getQueryBuilderForTable('sys_refindex');
628 $rows = $queryBuilder
629 ->select('*')
630 ->from('sys_refindex')
631 ->where(
632 $queryBuilder->expr()->eq(
633 'tablename',
634 $queryBuilder->createNamedParameter($table, \PDO::PARAM_STR)
635 ),
636 $queryBuilder->expr()->eq(
637 'recuid',
638 $queryBuilder->createNamedParameter($ref, \PDO::PARAM_INT)
639 )
640 )
641 ->execute()
642 ->fetchAll();
643
644 // Compile information for title tag:
645 foreach ($rows as $row) {
646 $line = [];
647 $record = BackendUtility::getRecord($row['ref_table'], $row['ref_uid']);
648 if ($record) {
649 $urlParameters = [
650 'edit' => [
651 $row['ref_table'] => [
652 $row['ref_uid'] => 'edit'
653 ]
654 ],
655 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
656 ];
657 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
658 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
659 $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
660 $line['url'] = $url;
661 $line['icon'] = $this->iconFactory->getIconForRecord($row['tablename'], $record, Icon::SIZE_SMALL)->render();
662 $line['row'] = $row;
663 $line['record'] = $record;
664 $line['recordTitle'] = BackendUtility::getRecordTitle($row['ref_table'], $record, false, true);
665 $line['title'] = $lang->sL($GLOBALS['TCA'][$row['ref_table']]['ctrl']['title']);
666 $line['labelForTableColumn'] = $this->getLabelForTableColumn($table, $row['field']);
667 $line['actions'] = $this->getRecordActions($row['ref_table'], $row['ref_uid']);
668 } else {
669 $line['row'] = $row;
670 $line['title'] = $lang->sL($GLOBALS['TCA'][$row['ref_table']]['ctrl']['title']);
671 $line['labelForTableColumn'] = $this->getLabelForTableColumn($table, $row['field']);
672 }
673 $refFromLines[] = $line;
674 }
675 return $refFromLines;
676 }
677
678 /**
679 * Convert FAL file reference (sys_file_reference) to reference index (sys_refindex) table format
680 *
681 * @param array $referenceRecord
682 * @return array
683 */
684 protected function transformFileReferenceToRecordReference(array $referenceRecord)
685 {
686 /** @var $queryBuilder \TYPO3\CMS\Core\Database\Query\QueryBuilder */
687 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
688 ->getQueryBuilderForTable('sys_file_reference');
689 $queryBuilder->getRestrictions()->removeAll();
690 $fileReference = $queryBuilder
691 ->select('*')
692 ->from('sys_file_reference')
693 ->where(
694 $queryBuilder->expr()->eq(
695 'uid',
696 $queryBuilder->createNamedParameter($referenceRecord['recuid'], \PDO::PARAM_INT)
697 )
698 )
699 ->execute()
700 ->fetch();
701
702 return [
703 'recuid' => $fileReference['uid_foreign'],
704 'tablename' => $fileReference['tablenames'],
705 'field' => $fileReference['fieldname'],
706 'flexpointer' => '',
707 'softref_key' => '',
708 'sorting' => $fileReference['sorting_foreign']
709 ];
710 }
711
712 /**
713 * Returns LanguageService
714 *
715 * @return \TYPO3\CMS\Core\Localization\LanguageService
716 */
717 protected function getLanguageService()
718 {
719 return $GLOBALS['LANG'];
720 }
721
722 /**
723 * Returns the current BE user.
724 *
725 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
726 */
727 protected function getBackendUser()
728 {
729 return $GLOBALS['BE_USER'];
730 }
731 }