ElementInformationController.php 27.5 KB
Newer Older
1
2
3
<?php
namespace TYPO3\CMS\Backend\Controller\ContentElement;

4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
16

17
use Psr\Http\Message\ResponseInterface;
18
19
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Backend\Avatar\Avatar;
20
use TYPO3\CMS\Backend\Template\ModuleTemplate;
Nicole Cordes's avatar
Nicole Cordes committed
21
use TYPO3\CMS\Backend\Utility\BackendUtility;
22
use TYPO3\CMS\Core\Database\ConnectionPool;
23
24
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
25
use TYPO3\CMS\Core\Resource\AbstractFile;
26
27
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Resource\ResourceFactory;
28
use TYPO3\CMS\Core\Type\Bitmask\Permission;
Nicole Cordes's avatar
Nicole Cordes committed
29
use TYPO3\CMS\Core\Utility\GeneralUtility;
30
use TYPO3\CMS\Fluid\View\StandaloneView;
Nicole Cordes's avatar
Nicole Cordes committed
31

32
33
34
/**
 * Script Class for showing information about an item.
 */
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class ElementInformationController
{
    /**
     * Record table name
     *
     * @var string
     */
    public $table;

    /**
     * Record uid
     *
     * @var int
     */
    public $uid;

    /**
     * @var string
     */
    protected $permsClause;

    /**
     * @var bool
     */
    public $access = false;

    /**
     * Which type of element:
     * - "file"
     * - "db"
     *
     * @var string
     */
    public $type = '';

    /**
71
     * @var ModuleTemplate
72
     */
73
    protected $moduleTemplate;
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

    /**
     * For type "db": Set to page record of the parent page of the item set
     * (if type="db")
     *
     * @var array
     */
    public $pageInfo;

    /**
     * Database records identified by table/uid
     *
     * @var array
     */
    protected $row;

    /**
     * @var \TYPO3\CMS\Core\Resource\File
     */
    protected $fileObject;

    /**
     * @var Folder
     */
    protected $folderObject;

    /**
     * @var IconFactory
     */
    protected $iconFactory;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
        $GLOBALS['SOBE'] = $this;

        $this->init();
    }

    /**
     * Determines if table/uid point to database record or file and
     * if user has access to view information
     */
    public function init()
    {
        $this->table = GeneralUtility::_GET('table');
        $this->uid = GeneralUtility::_GET('uid');

125
        $this->permsClause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW);
126
127
        $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
        $this->moduleTemplate->getDocHeaderComponent()->disable();
128
129
130

        if (isset($GLOBALS['TCA'][$this->table])) {
            $this->initDatabaseRecord();
131
        } elseif ($this->table === '_FILE' || $this->table === '_FOLDER' || $this->table === 'sys_file') {
132
133
134
135
136
137
138
139
140
141
142
143
144
145
            $this->initFileOrFolderRecord();
        }
    }

    /**
     * Init database records (table)
     */
    protected function initDatabaseRecord()
    {
        $this->type = 'db';
        $this->uid = (int)$this->uid;

        // Check permissions and uid value:
        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
150
151
152
153
                $this->row = $this->pageInfo;
            } else {
                $this->row = BackendUtility::getRecordWSOL($this->table, $this->uid);
                if ($this->row) {
                    $this->pageInfo = BackendUtility::readPageAccess($this->row['pid'], $this->permsClause);
154
                    $this->access = is_array($this->pageInfo);
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
                }
            }
        }
    }

    /**
     * Init file/folder parameters
     */
    protected function initFileOrFolderRecord()
    {
        $fileOrFolderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->uid);

        if ($fileOrFolderObject instanceof Folder) {
            $this->folderObject = $fileOrFolderObject;
            $this->access = $this->folderObject->checkActionPermission('read');
            $this->type = 'folder';
        } else {
            $this->fileObject = $fileOrFolderObject;
            $this->access = $this->fileObject->checkActionPermission('read');
            $this->type = 'file';
            $this->table = 'sys_file';

            try {
                $this->row = BackendUtility::getRecordWSOL($this->table, $fileOrFolderObject->getUid());
            } catch (\Exception $e) {
180
                $this->row = [];
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
            }
        }
    }

    /**
     * Injects the request object for the current request or subrequest
     * As this controller goes only through the main() method, it is rather simple for now
     *
     * @param ServerRequestInterface $request the current request
     * @param ResponseInterface $response
     * @return ResponseInterface the response with the content
     */
    public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
    {
        $this->main();

197
        $response->getBody()->write($this->moduleTemplate->renderContent());
198
199
200
201
        return $response;
    }

    /**
202
203
     * Compiles the whole content to be outputted, which is then set as content to the moduleTemplate
     * There is a hook to do a custom rendering of a record.
204
205
206
     */
    public function main()
    {
207
208
        $content = '';

209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
        // Rendering of the output via fluid
        $view = GeneralUtility::makeInstance(StandaloneView::class);
        $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
        $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
            'EXT:backend/Resources/Private/Templates/ContentElement/ElementInformation.html'
        ));

        if ($this->access) {
            // render type by user func
            $typeRendered = false;
            foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] ?? [] as $className) {
                $typeRenderObj = GeneralUtility::makeInstance($className);
                if (is_object($typeRenderObj) && method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render')) {
                    if ($typeRenderObj->isValid($this->type, $this)) {
                        $content .= $typeRenderObj->render($this->type, $this);
                        $typeRendered = true;
                        break;
                    }
228
229
230
                }
            }

231
232
233
234
235
236
237
238
239
240
241
            if (!$typeRendered) {
                $view->assign('accessAllowed', true);
                $view->assignMultiple($this->getPageTitle());
                $view->assignMultiple($this->getPreview());
                $view->assignMultiple($this->getPropertiesForTable());
                $view->assignMultiple($this->getReferences());
                $view->assignMultiple($this->getBackButton());
                $view->assign('maxTitleLength', $this->getBackendUser()->uc['titleLen'] ?? 20);
                $content .=  $view->render();
            }
        } 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
260
            $pageTitle['table'] = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:folder');
            $pageTitle['icon'] = $this->iconFactory->getIconForResource($this->folderObject, Icon::SIZE_SMALL)->render();
261
        } elseif ($this->type === 'file') {
262
263
            $pageTitle['table'] = $this->getLanguageService()->sL($GLOBALS['TCA'][$this->table]['ctrl']['title']);
            $pageTitle['icon'] = $this->iconFactory->getIconForResource($this->fileObject, Icon::SIZE_SMALL)->render();
264
        } else {
265
266
            $pageTitle['table'] = $this->getLanguageService()->sL($GLOBALS['TCA'][$this->table]['ctrl']['title']);
            $pageTitle['icon'] = $this->iconFactory->getIconForRecord($this->table, $this->row, Icon::SIZE_SMALL);
267
        }
268
269
        $this->moduleTemplate->setTitle($pageTitle['table'] . ': ' . $pageTitle['title']);
        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
281
        // Perhaps @todo in future: Also display preview for records - without fileObject
        if (!$this->fileObject) {
282
            return $preview;
283
284
285
286
        }

        // check if file is marked as missing
        if ($this->fileObject->isMissing()) {
287
            $preview['missingFile'] =$this->fileObject->getName();
288
289
290
291
292
        } else {
            /** @var \TYPO3\CMS\Core\Resource\Rendering\RendererRegistry $rendererRegistry */
            $rendererRegistry = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Rendering\RendererRegistry::class);
            $fileRenderer = $rendererRegistry->getRenderer($this->fileObject);
            $fileExtension = $this->fileObject->getExtension();
293
294
295
296
            $preview['url'] = $this->fileObject->getPublicUrl(true);

            $width = '590m';
            $heigth = '400m';
297
298
299

            // Check if there is a FileRenderer
            if ($fileRenderer !== null) {
300
                $preview['fileRenderer'] = $fileRenderer->render(
301
                    $this->fileObject,
302
303
                    $width,
                    $heigth,
304
                    [],
305
306
307
                    true
                );

308
                // else check if we can create an Image preview
309
            } elseif (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
310
311
312
                $preview['fileObject'] = $this->fileObject;
                $preview['width'] = $width;
                $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
329
330
331

        $extraFields = [
            'uid' => htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.uid'))
        ];

332
        if (in_array($this->type, ['folder', 'file'], true)) {
333
            if ($this->type === 'file') {
334
335
                $extraFields['creation_date'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.creationDate'));
                $extraFields['modification_date'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.timestamp'));
336
337
338
339
                if ($this->fileObject->getType() === AbstractFile::FILETYPE_IMAGE) {
                    $extraFields['width'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.width'));
                    $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'));
            $extraFields['folder'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:folder'));
343
        } else {
344
345
346
            $extraFields['crdate'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.creationDate'));
            $extraFields['cruser_id'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.creationUserId'));
            $extraFields['tstamp'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.timestamp'));
347
348
349
350
351

            // check if the special fields are defined in the TCA ctrl section of the table
            foreach ($extraFields as $fieldName => $fieldLabel) {
                if (isset($GLOBALS['TCA'][$this->table]['ctrl'][$fieldName])) {
                    $extraFields[$GLOBALS['TCA'][$this->table]['ctrl'][$fieldName]] = $fieldLabel;
352
                } elseif ($fieldName !== 'uid') {
353
354
355
356
357
358
359
                    unset($extraFields[$fieldName]);
                }
            }
        }

        foreach ($extraFields as $name => $fieldLabel) {
            $rowValue = '';
360
            $thisRow = [];
361
362
363
364
365
366
            if (!isset($this->row[$name])) {
                $resourceObject = $this->fileObject ?: $this->folderObject;
                if ($name === 'storage') {
                    $rowValue = $resourceObject->getStorage()->getName();
                } elseif ($name === 'folder') {
                    $rowValue = $resourceObject->getParentFolder()->getReadablePath();
367
368
369
370
                } elseif ($name === 'width') {
                    $rowValue = $this->fileObject->getProperty('width') . 'px';
                } elseif ($name === 'height') {
                    $rowValue = $this->fileObject->getProperty('height') . 'px';
371
                }
372
            } elseif ($name === 'creation_date' || $name === 'modification_date') {
373
374
375
376
                $rowValue = BackendUtility::datetime($this->row[$name]);
            } else {
                $rowValue = BackendUtility::getProcessedValueExtra($this->table, $name, $this->row[$name]);
            }
377
378
            $thisRow['value'] = $rowValue;
            $thisRow['fieldLabel'] = rtrim($fieldLabel, ':');
379
380
381
382
383
384
            // show the backend username who created the issue
            if ($name === 'cruser_id' && $rowValue) {
                $creatorRecord = BackendUtility::getRecord('be_users', $rowValue);
                if ($creatorRecord) {
                    /** @var Avatar $avatar */
                    $avatar = GeneralUtility::makeInstance(Avatar::class);
385
386
387
                    $creatorRecord['icon'] = $avatar->render($creatorRecord);
                    $thisRow['creatorRecord'] = $creatorRecord;
                    $thisRow['value'] = '';
388
389
                }
            }
390
            $propertiesForTable['extraFields'][] = $thisRow;
391
392
393
394
395
        }

        // Traverse the list of fields to display for the record:
        $fieldList = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$this->table]['interface']['showRecordFieldList'], true);
        foreach ($fieldList as $name) {
396
            $thisRow = [];
397
398
399
400
401
402
403
404
405
406
407
408
            $name = trim($name);
            $uid = $this->row['uid'];

            if (!isset($GLOBALS['TCA'][$this->table]['columns'][$name])) {
                continue;
            }

            // Storage is already handled above
            if ($this->type === 'file' && $name === 'storage') {
                continue;
            }

409
410
            // format file size as bytes/kilobytes/megabytes
            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
415
416
417
418
            $isExcluded = !(!$GLOBALS['TCA'][$this->table]['columns'][$name]['exclude'] || $this->getBackendUser()->check('non_exclude_fields', $this->table . ':' . $name));
            if ($isExcluded) {
                continue;
            }

419
420
421
            $thisRow['fieldValue'] = BackendUtility::getProcessedValue($this->table, $name, $this->row[$name], 0, 0, false, $uid);
            $thisRow['fieldLabel'] = htmlspecialchars($lang->sL(BackendUtility::getItemLabel($this->table, $name)));
            $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
435
        switch ($this->type) {
            case 'db': {
436
437
                $references['refLines'] = $this->makeRef($this->table, $this->row['uid']);
                $references['refFromLines'] = $this->makeRefFrom($this->table, $this->row['uid']);
438
439
440
441
442
                break;
            }

            case 'file': {
                if ($this->fileObject && $this->fileObject->isIndexed()) {
443
                    $references['refLines'] = $this->makeRef('_FILE', $this->fileObject);
444
445
446
447
                }
                break;
            }
        }
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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
    }

    /**
     * Get field name for specified table/column name
     *
     * @param string $tableName Table name
     * @param string $fieldName Column name
     * @return string label
     */
    public function getLabelForTableColumn($tableName, $fieldName)
    {
        if ($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label'] !== null) {
            $field = $this->getLanguageService()->sL($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label']);
            if (trim($field) === '') {
                $field = $fieldName;
            }
        } else {
            $field = $fieldName;
        }
        return $field;
    }

    /**
482
     * Returns the record actions
483
484
485
     *
     * @param string $table
     * @param int $uid
486
     * @return array
487
488
489
490
     */
    protected function getRecordActions($table, $uid)
    {
        if ($table === '' || $uid < 0) {
491
            return [];
492
493
        }

494
        $actions = [];
495
496
497
498
499
500
501
502
503
        // Edit button
        $urlParameters = [
            'edit' => [
                $table => [
                    $uid => 'edit'
                ]
            ],
            'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
        ];
504
505
506
        /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
        $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
        $actions['recordEditUrl'] = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
Benjamin Kott's avatar
Benjamin Kott committed
507

508
509
510
511
512
        // History button
        $urlParameters = [
            'element' => $table . ':' . $uid,
            'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
        ];
513
        $actions['recordHistoryUrl'] = (string)$uriBuilder->buildUriFromRoute('record_history', $urlParameters);
514

515
516
        if ($table === 'pages') {
            // Recordlist button
517
            $actions['webListUrl'] = (string)$uriBuilder->buildUriFromRoute('web_list', ['id' => $uid, 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')]);
Benjamin Kott's avatar
Benjamin Kott committed
518

519
            // View page button
520
            $actions['viewOnClick'] = BackendUtility::viewOnClick($uid, '', BackendUtility::BEgetRootLine($uid));
521
        }
Benjamin Kott's avatar
Benjamin Kott committed
522

523
        return $actions;
524
525
526
527
528
529
530
    }

    /**
     * Make reference display
     *
     * @param string $table Table name
     * @param string|\TYPO3\CMS\Core\Resource\File $ref Filename or uid
531
     * @return array
532
533
534
     */
    protected function makeRef($table, $ref)
    {
535
        $refLines = [];
536
537
538
539
540
541
542
543
544
        $lang = $this->getLanguageService();
        // Files reside in sys_file table
        if ($table === '_FILE') {
            $selectTable = 'sys_file';
            $selectUid = $ref->getUid();
        } else {
            $selectTable = $table;
            $selectUid = $ref;
        }
545
        /** @var $queryBuilder \TYPO3\CMS\Core\Database\Query\QueryBuilder */
546
547
548
549
550
551
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getQueryBuilderForTable('sys_refindex');
        $rows = $queryBuilder
            ->select('*')
            ->from('sys_refindex')
            ->where(
552
553
554
555
556
557
558
559
560
561
562
563
                $queryBuilder->expr()->eq(
                    'ref_table',
                    $queryBuilder->createNamedParameter($selectTable, \PDO::PARAM_STR)
                ),
                $queryBuilder->expr()->eq(
                    'ref_uid',
                    $queryBuilder->createNamedParameter($selectUid, \PDO::PARAM_INT)
                ),
                $queryBuilder->expr()->eq(
                    'deleted',
                    $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
                )
564
565
566
            )
            ->execute()
            ->fetchAll();
567
568
569
570
571
572

        // Compile information for title tag:
        foreach ($rows as $row) {
            if ($row['tablename'] === 'sys_file_reference') {
                $row = $this->transformFileReferenceToRecordReference($row);
                if ($row['tablename'] === null || $row['recuid'] === null) {
573
                    return;
574
575
                }
            }
576
            $line = [];
577
578
579
580
581
582
583
584
585
586
587
588
589
590
            $record = BackendUtility::getRecord($row['tablename'], $row['recuid']);
            if ($record) {
                $parentRecord = BackendUtility::getRecord('pages', $record['pid']);
                $parentRecordTitle = is_array($parentRecord)
                    ? BackendUtility::getRecordTitle('pages', $parentRecord)
                    : '';
                $urlParameters = [
                    'edit' => [
                        $row['tablename'] => [
                            $row['recuid'] => 'edit'
                        ]
                    ],
                    'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
                ];
591
592
593
                /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
                $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
                $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
594
595
596
597
                $line['url'] = $url;
                $line['icon'] = $this->iconFactory->getIconForRecord($row['tablename'], $record, Icon::SIZE_SMALL)->render();
                $line['row'] = $row;
                $line['record'] = $record;
598
                $line['recordTitle'] = BackendUtility::getRecordTitle($row['tablename'], $record, false, true);
599
600
601
602
                $line['parentRecordTitle'] = $parentRecordTitle;
                $line['title'] = $lang->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title']);
                $line['labelForTableColumn'] = $this->getLabelForTableColumn($row['tablename'], $row['field']);
                $line['actions'] = $this->getRecordActions($row['tablename'], $row['recuid']);
603
            } else {
604
605
606
                $line['row'] = $row;
                $line['title'] = $lang->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title']) ?: $row['tablename'];
                $line['labelForTableColumn'] = $this->getLabelForTableColumn($row['tablename'], $row['field']);
607
            }
608
            $refLines[] = $line;
609
        }
610
        return $refLines;
611
612
613
614
615
616
617
    }

    /**
     * Make reference display (what this elements points to)
     *
     * @param string $table Table name
     * @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
627
628
629
630
631
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getQueryBuilderForTable('sys_refindex');
        $rows = $queryBuilder
            ->select('*')
            ->from('sys_refindex')
            ->where(
632
633
634
635
636
637
638
639
                $queryBuilder->expr()->eq(
                    'tablename',
                    $queryBuilder->createNamedParameter($table, \PDO::PARAM_STR)
                ),
                $queryBuilder->expr()->eq(
                    'recuid',
                    $queryBuilder->createNamedParameter($ref, \PDO::PARAM_INT)
                )
640
641
642
            )
            ->execute()
            ->fetchAll();
643
644
645

        // Compile information for title tag:
        foreach ($rows as $row) {
646
            $line = [];
647
648
649
650
651
652
653
654
655
656
            $record = BackendUtility::getRecord($row['ref_table'], $row['ref_uid']);
            if ($record) {
                $urlParameters = [
                    'edit' => [
                        $row['ref_table'] => [
                            $row['ref_uid'] => 'edit'
                        ]
                    ],
                    'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
                ];
657
658
659
                /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
                $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
                $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
660
661
662
663
                $line['url'] = $url;
                $line['icon'] = $this->iconFactory->getIconForRecord($row['tablename'], $record, Icon::SIZE_SMALL)->render();
                $line['row'] = $row;
                $line['record'] = $record;
664
                $line['recordTitle'] = BackendUtility::getRecordTitle($row['ref_table'], $record, false, true);
665
666
667
                $line['title'] = $lang->sL($GLOBALS['TCA'][$row['ref_table']]['ctrl']['title']);
                $line['labelForTableColumn'] = $this->getLabelForTableColumn($table, $row['field']);
                $line['actions'] = $this->getRecordActions($row['ref_table'], $row['ref_uid']);
668
            } else {
669
670
671
                $line['row'] = $row;
                $line['title'] = $lang->sL($GLOBALS['TCA'][$row['ref_table']]['ctrl']['title']);
                $line['labelForTableColumn'] = $this->getLabelForTableColumn($table, $row['field']);
672
            }
673
            $refFromLines[] = $line;
674
        }
675
        return $refFromLines;
676
677
678
679
680
681
682
683
684
685
    }

    /**
     * Convert FAL file reference (sys_file_reference) to reference index (sys_refindex) table format
     *
     * @param array $referenceRecord
     * @return array
     */
    protected function transformFileReferenceToRecordReference(array $referenceRecord)
    {
686
        /** @var $queryBuilder \TYPO3\CMS\Core\Database\Query\QueryBuilder */
687
688
689
690
691
692
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getQueryBuilderForTable('sys_file_reference');
        $queryBuilder->getRestrictions()->removeAll();
        $fileReference = $queryBuilder
            ->select('*')
            ->from('sys_file_reference')
693
694
695
696
697
698
            ->where(
                $queryBuilder->expr()->eq(
                    'uid',
                    $queryBuilder->createNamedParameter($referenceRecord['recuid'], \PDO::PARAM_INT)
                )
            )
699
700
701
            ->execute()
            ->fetch();

702
        return [
703
704
705
706
707
708
            'recuid' => $fileReference['uid_foreign'],
            'tablename' => $fileReference['tablenames'],
            'field' => $fileReference['fieldname'],
            'flexpointer' => '',
            'softref_key' => '',
            'sorting' => $fileReference['sorting_foreign']
709
        ];
710
711
712
713
714
    }

    /**
     * Returns LanguageService
     *
715
     * @return \TYPO3\CMS\Core\Localization\LanguageService
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
     */
    protected function getLanguageService()
    {
        return $GLOBALS['LANG'];
    }

    /**
     * Returns the current BE user.
     *
     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
     */
    protected function getBackendUser()
    {
        return $GLOBALS['BE_USER'];
    }
731
}