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