d8f62f59d5f85ae8918c5c8b6982e4b233481272
[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) ? 1 : 0;
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) ? 1 : 0;
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 if (!$this->access) {
207 return;
208 }
209
210 $content = '';
211
212 // render type by user func
213 $typeRendered = false;
214 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'])) {
215 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] as $className) {
216 $typeRenderObj = GeneralUtility::makeInstance($className);
217 if (method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render')) {
218 if ($typeRenderObj->isValid($this->type, $this)) {
219 $content .= $typeRenderObj->render($this->type, $this);
220 $typeRendered = true;
221 break;
222 }
223 }
224 }
225 }
226
227 if (!$typeRendered) {
228 // Rendering of the output via fluid
229 $view = GeneralUtility::makeInstance(StandaloneView::class);
230 $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
231 $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
232 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
233 'EXT:backend/Resources/Private/Templates/ContentElement/ElementInformation.html'
234 ));
235 $view->assignMultiple($this->getPageTitle());
236 $view->assignMultiple($this->getPreview());
237 $view->assignMultiple($this->getPropertiesForTable());
238 $view->assignMultiple($this->getReferences());
239 $view->assignMultiple($this->getBackButton());
240 $content .= $view->render();
241 }
242 $this->moduleTemplate->setContent($content);
243 }
244
245 /**
246 * Get page title with icon, table title and record title
247 *
248 * @return array
249 */
250 protected function getPageTitle() : array
251 {
252 $pageTitle = [
253 'title' => strip_tags(BackendUtility::getRecordTitle($this->table, $this->row))
254 ];
255 if ($this->type === 'folder') {
256 $pageTitle['table'] = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:folder');
257 $pageTitle['icon'] = $this->iconFactory->getIconForResource($this->folderObject, Icon::SIZE_SMALL)->render();
258 } elseif ($this->type === 'file') {
259 $pageTitle['table'] = $this->getLanguageService()->sL($GLOBALS['TCA'][$this->table]['ctrl']['title']);
260 $pageTitle['icon'] = $this->iconFactory->getIconForResource($this->fileObject, Icon::SIZE_SMALL)->render();
261 } else {
262 $pageTitle['table'] = $this->getLanguageService()->sL($GLOBALS['TCA'][$this->table]['ctrl']['title']);
263 $pageTitle['icon'] = $this->iconFactory->getIconForRecord($this->table, $this->row, Icon::SIZE_SMALL);
264 }
265 $this->moduleTemplate->setTitle($pageTitle['table'] . ': ' . $pageTitle['title']);
266 return $pageTitle;
267 }
268
269 /**
270 * Get preview for current record
271 *
272 * @return array
273 */
274 protected function getPreview() : array
275 {
276 $preview = [];
277 // Perhaps @todo in future: Also display preview for records - without fileObject
278 if (!$this->fileObject) {
279 return $preview;
280 }
281
282 // check if file is marked as missing
283 if ($this->fileObject->isMissing()) {
284 $preview['missingFile'] =$this->fileObject->getName();
285 } else {
286 /** @var \TYPO3\CMS\Core\Resource\Rendering\RendererRegistry $rendererRegistry */
287 $rendererRegistry = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Rendering\RendererRegistry::class);
288 $fileRenderer = $rendererRegistry->getRenderer($this->fileObject);
289 $fileExtension = $this->fileObject->getExtension();
290 $preview['url'] = $this->fileObject->getPublicUrl(true);
291
292 $width = '590m';
293 $heigth = '400m';
294
295 // Check if there is a FileRenderer
296 if ($fileRenderer !== null) {
297 $preview['fileRenderer'] = $fileRenderer->render(
298 $this->fileObject,
299 $width,
300 $heigth,
301 [],
302 true
303 );
304
305 // else check if we can create an Image preview
306 } elseif (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
307 $preview['fileObject'] = $this->fileObject;
308 $preview['width'] = $width;
309 $preview['heigth'] = $heigth;
310 }
311 }
312 return $preview;
313 }
314
315 /**
316 * Get property array for html table
317 *
318 * @return array
319 */
320 protected function getPropertiesForTable() : array
321 {
322 $propertiesForTable = [];
323 $extraFields = [];
324
325 $lang = $this->getLanguageService();
326 if (in_array($this->type, ['folder', 'file'], true)) {
327 if ($this->type === 'file') {
328 $extraFields['creation_date'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.creationDate'));
329 $extraFields['modification_date'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.timestamp'));
330 if ($this->fileObject->getType() === AbstractFile::FILETYPE_IMAGE) {
331 $extraFields['width'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.width'));
332 $extraFields['height'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.height'));
333 }
334 }
335 $extraFields['storage'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file.storage'));
336 $extraFields['folder'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:folder'));
337 } else {
338 $extraFields['crdate'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.creationDate'));
339 $extraFields['cruser_id'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.creationUserId'));
340 $extraFields['tstamp'] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.timestamp'));
341
342 // check if the special fields are defined in the TCA ctrl section of the table
343 foreach ($extraFields as $fieldName => $fieldLabel) {
344 if (isset($GLOBALS['TCA'][$this->table]['ctrl'][$fieldName])) {
345 $extraFields[$GLOBALS['TCA'][$this->table]['ctrl'][$fieldName]] = $fieldLabel;
346 } else {
347 unset($extraFields[$fieldName]);
348 }
349 }
350 }
351
352 foreach ($extraFields as $name => $fieldLabel) {
353 $rowValue = '';
354 $thisRow = [];
355 if (!isset($this->row[$name])) {
356 $resourceObject = $this->fileObject ?: $this->folderObject;
357 if ($name === 'storage') {
358 $rowValue = $resourceObject->getStorage()->getName();
359 } elseif ($name === 'folder') {
360 $rowValue = $resourceObject->getParentFolder()->getReadablePath();
361 } elseif ($name === 'width') {
362 $rowValue = $this->fileObject->getProperty('width') . 'px';
363 } elseif ($name === 'height') {
364 $rowValue = $this->fileObject->getProperty('height') . 'px';
365 }
366 } elseif ($name === 'creation_date' || $name === 'modification_date') {
367 $rowValue = BackendUtility::datetime($this->row[$name]);
368 } else {
369 $rowValue = BackendUtility::getProcessedValueExtra($this->table, $name, $this->row[$name]);
370 }
371 $thisRow['value'] = $rowValue;
372 $thisRow['fieldLabel'] = rtrim($fieldLabel, ':');
373 // show the backend username who created the issue
374 if ($name === 'cruser_id' && $rowValue) {
375 $creatorRecord = BackendUtility::getRecord('be_users', $rowValue);
376 if ($creatorRecord) {
377 /** @var Avatar $avatar */
378 $avatar = GeneralUtility::makeInstance(Avatar::class);
379 $creatorRecord['icon'] = $avatar->render($creatorRecord);
380 $thisRow['creatorRecord'] = $creatorRecord;
381 $thisRow['value'] = '';
382 }
383 }
384 $propertiesForTable['extraFields'][] = $thisRow;
385 }
386
387 // Traverse the list of fields to display for the record:
388 $fieldList = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$this->table]['interface']['showRecordFieldList'], true);
389 foreach ($fieldList as $name) {
390 $thisRow = [];
391 $name = trim($name);
392 $uid = $this->row['uid'];
393
394 if (!isset($GLOBALS['TCA'][$this->table]['columns'][$name])) {
395 continue;
396 }
397
398 // Storage is already handled above
399 if ($this->type === 'file' && $name === 'storage') {
400 continue;
401 }
402
403 // format file size as bytes/kilobytes/megabytes
404 if ($this->type === 'file' && $name === 'size') {
405 $this->row[$name] = GeneralUtility::formatSize($this->row[$name], htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:byteSizeUnits')));
406 }
407
408 $isExcluded = !(!$GLOBALS['TCA'][$this->table]['columns'][$name]['exclude'] || $this->getBackendUser()->check('non_exclude_fields', $this->table . ':' . $name));
409 if ($isExcluded) {
410 continue;
411 }
412
413 $thisRow['fieldValue'] = BackendUtility::getProcessedValue($this->table, $name, $this->row[$name], 0, 0, false, $uid);
414 $thisRow['fieldLabel'] = htmlspecialchars($lang->sL(BackendUtility::getItemLabel($this->table, $name)));
415 $propertiesForTable['fields'][] = $thisRow;
416 }
417 return $propertiesForTable;
418 }
419
420 /**
421 * Get references section (references from and references to current record)
422 *
423 * @return array
424 */
425 protected function getReferences() : array
426 {
427 $references = [];
428 switch ($this->type) {
429 case 'db': {
430 $references['refLines'] = $this->makeRef($this->table, $this->row['uid']);
431 $references['refFromLines'] = $this->makeRefFrom($this->table, $this->row['uid']);
432 break;
433 }
434
435 case 'file': {
436 if ($this->fileObject && $this->fileObject->isIndexed()) {
437 $references['refLines'] = $this->makeRef('_FILE', $this->fileObject);
438 }
439 break;
440 }
441 }
442 return $references;
443 }
444
445 /**
446 * Get a back button, if a returnUrl was provided
447 *
448 * @return array
449 */
450 protected function getBackButton() : array
451 {
452 return ['returnUrl' => GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GET('returnUrl'))];
453 }
454
455 /**
456 * Get field name for specified table/column name
457 *
458 * @param string $tableName Table name
459 * @param string $fieldName Column name
460 * @return string label
461 */
462 public function getLabelForTableColumn($tableName, $fieldName)
463 {
464 if ($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label'] !== null) {
465 $field = $this->getLanguageService()->sL($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label']);
466 if (trim($field) === '') {
467 $field = $fieldName;
468 }
469 } else {
470 $field = $fieldName;
471 }
472 return $field;
473 }
474
475 /**
476 * Returns the record actions
477 *
478 * @param string $table
479 * @param int $uid
480 * @return array
481 */
482 protected function getRecordActions($table, $uid)
483 {
484 if ($table === '' || $uid < 0) {
485 return [];
486 }
487
488 $actions = [];
489 // Edit button
490 $urlParameters = [
491 'edit' => [
492 $table => [
493 $uid => 'edit'
494 ]
495 ],
496 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
497 ];
498 $actions['recordEditUrl'] = BackendUtility::getModuleUrl('record_edit', $urlParameters);
499
500 // History button
501 $urlParameters = [
502 'element' => $table . ':' . $uid,
503 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
504 ];
505 $actions['recordHistoryUrl'] = BackendUtility::getModuleUrl('record_history', $urlParameters);
506
507 if ($table === 'pages') {
508 // Recordlist button
509 $actions['webListUrl'] = BackendUtility::getModuleUrl('web_list', ['id' => $uid, 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')]);
510
511 // View page button
512 $actions['viewOnClick'] = BackendUtility::viewOnClick($uid, '', BackendUtility::BEgetRootLine($uid));
513 }
514
515 return $actions;
516 }
517
518 /**
519 * Make reference display
520 *
521 * @param string $table Table name
522 * @param string|\TYPO3\CMS\Core\Resource\File $ref Filename or uid
523 * @return array
524 */
525 protected function makeRef($table, $ref)
526 {
527 $refLines = [];
528 $lang = $this->getLanguageService();
529 // Files reside in sys_file table
530 if ($table === '_FILE') {
531 $selectTable = 'sys_file';
532 $selectUid = $ref->getUid();
533 } else {
534 $selectTable = $table;
535 $selectUid = $ref;
536 }
537 /** @var $queryBuilder \TYPO3\CMS\Core\Database\Query\QueryBuilder */
538 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
539 ->getQueryBuilderForTable('sys_refindex');
540 $rows = $queryBuilder
541 ->select('*')
542 ->from('sys_refindex')
543 ->where(
544 $queryBuilder->expr()->eq(
545 'ref_table',
546 $queryBuilder->createNamedParameter($selectTable, \PDO::PARAM_STR)
547 ),
548 $queryBuilder->expr()->eq(
549 'ref_uid',
550 $queryBuilder->createNamedParameter($selectUid, \PDO::PARAM_INT)
551 ),
552 $queryBuilder->expr()->eq(
553 'deleted',
554 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
555 )
556 )
557 ->execute()
558 ->fetchAll();
559
560 // Compile information for title tag:
561 foreach ($rows as $row) {
562 if ($row['tablename'] === 'sys_file_reference') {
563 $row = $this->transformFileReferenceToRecordReference($row);
564 if ($row['tablename'] === null || $row['recuid'] === null) {
565 return;
566 }
567 }
568 $line = [];
569 $record = BackendUtility::getRecord($row['tablename'], $row['recuid']);
570 if ($record) {
571 $parentRecord = BackendUtility::getRecord('pages', $record['pid']);
572 $parentRecordTitle = is_array($parentRecord)
573 ? BackendUtility::getRecordTitle('pages', $parentRecord)
574 : '';
575 $urlParameters = [
576 'edit' => [
577 $row['tablename'] => [
578 $row['recuid'] => 'edit'
579 ]
580 ],
581 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
582 ];
583 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
584 $line['url'] = $url;
585 $line['icon'] = $this->iconFactory->getIconForRecord($row['tablename'], $record, Icon::SIZE_SMALL)->render();
586 $line['row'] = $row;
587 $line['record'] = $record;
588 $line['recordTitle'] = BackendUtility::getRecordTitle($row['tablename'], $record, true);
589 $line['parentRecordTitle'] = $parentRecordTitle;
590 $line['title'] = $lang->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title']);
591 $line['labelForTableColumn'] = $this->getLabelForTableColumn($row['tablename'], $row['field']);
592 $line['actions'] = $this->getRecordActions($row['tablename'], $row['recuid']);
593 } else {
594 $line['row'] = $row;
595 $line['title'] = $lang->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title']) ?: $row['tablename'];
596 $line['labelForTableColumn'] = $this->getLabelForTableColumn($row['tablename'], $row['field']);
597 }
598 $refLines[] = $line;
599 }
600 return $refLines;
601 }
602
603 /**
604 * Make reference display (what this elements points to)
605 *
606 * @param string $table Table name
607 * @param string $ref Filename or uid
608 * @return array
609 */
610 protected function makeRefFrom($table, $ref) : array
611 {
612 $refFromLines = [];
613 $lang = $this->getLanguageService();
614
615 /** @var $queryBuilder \TYPO3\CMS\Core\Database\Query\QueryBuilder */
616 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
617 ->getQueryBuilderForTable('sys_refindex');
618 $rows = $queryBuilder
619 ->select('*')
620 ->from('sys_refindex')
621 ->where(
622 $queryBuilder->expr()->eq(
623 'tablename',
624 $queryBuilder->createNamedParameter($table, \PDO::PARAM_STR)
625 ),
626 $queryBuilder->expr()->eq(
627 'recuid',
628 $queryBuilder->createNamedParameter($ref, \PDO::PARAM_INT)
629 )
630 )
631 ->execute()
632 ->fetchAll();
633
634 // Compile information for title tag:
635 foreach ($rows as $row) {
636 $line = [];
637 $record = BackendUtility::getRecord($row['ref_table'], $row['ref_uid']);
638 if ($record) {
639 $urlParameters = [
640 'edit' => [
641 $row['ref_table'] => [
642 $row['ref_uid'] => 'edit'
643 ]
644 ],
645 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
646 ];
647 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
648 $line['url'] = $url;
649 $line['icon'] = $this->iconFactory->getIconForRecord($row['tablename'], $record, Icon::SIZE_SMALL)->render();
650 $line['row'] = $row;
651 $line['record'] = $record;
652 $line['recordTitle'] = BackendUtility::getRecordTitle($row['ref_table'], $record, true);
653 $line['title'] = $lang->sL($GLOBALS['TCA'][$row['ref_table']]['ctrl']['title']);
654 $line['labelForTableColumn'] = $this->getLabelForTableColumn($table, $row['field']);
655 $line['actions'] = $this->getRecordActions($row['ref_table'], $row['ref_uid']);
656 } else {
657 $line['row'] = $row;
658 $line['title'] = $lang->sL($GLOBALS['TCA'][$row['ref_table']]['ctrl']['title']);
659 $line['labelForTableColumn'] = $this->getLabelForTableColumn($table, $row['field']);
660 }
661 $refFromLines[] = $line;
662 }
663 return $refFromLines;
664 }
665
666 /**
667 * Convert FAL file reference (sys_file_reference) to reference index (sys_refindex) table format
668 *
669 * @param array $referenceRecord
670 * @return array
671 */
672 protected function transformFileReferenceToRecordReference(array $referenceRecord)
673 {
674 /** @var $queryBuilder \TYPO3\CMS\Core\Database\Query\QueryBuilder */
675 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
676 ->getQueryBuilderForTable('sys_file_reference');
677 $queryBuilder->getRestrictions()->removeAll();
678 $fileReference = $queryBuilder
679 ->select('*')
680 ->from('sys_file_reference')
681 ->where(
682 $queryBuilder->expr()->eq(
683 'uid',
684 $queryBuilder->createNamedParameter($referenceRecord['recuid'], \PDO::PARAM_INT)
685 )
686 )
687 ->execute()
688 ->fetch();
689
690 return [
691 'recuid' => $fileReference['uid_foreign'],
692 'tablename' => $fileReference['tablenames'],
693 'field' => $fileReference['fieldname'],
694 'flexpointer' => '',
695 'softref_key' => '',
696 'sorting' => $fileReference['sorting_foreign']
697 ];
698 }
699
700 /**
701 * Returns LanguageService
702 *
703 * @return \TYPO3\CMS\Lang\LanguageService
704 */
705 protected function getLanguageService()
706 {
707 return $GLOBALS['LANG'];
708 }
709
710 /**
711 * Returns the current BE user.
712 *
713 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
714 */
715 protected function getBackendUser()
716 {
717 return $GLOBALS['BE_USER'];
718 }
719 }