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