[!!!][TASK] Improve flex and TCA handling in FormEngine
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / Service / UserFileInlineLabelService.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Service;
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 TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Resource\Exception\InvalidUidException;
19 use TYPO3\CMS\Core\Resource\Index\MetaDataRepository;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
22
23 /**
24 * User file inline label service
25 */
26 class UserFileInlineLabelService
27 {
28 /**
29 * Get the user function label for the file_reference table
30 *
31 * @param array $params
32 * @return void
33 */
34 public function getInlineLabel(array &$params)
35 {
36 $sysFileFields = isset($params['options']['sys_file']) && is_array($params['options']['sys_file'])
37 ? $params['options']['sys_file']
38 : [];
39
40 if (empty($sysFileFields)) {
41 // Nothing to do
42 $params['title'] = $params['row']['uid'];
43 return;
44 }
45
46 // In case of a group field uid_local is a resolved array
47 $fileRecord = $params['row']['uid_local'][0]['row'];
48
49 // Configuration
50 $title = [];
51 foreach ($sysFileFields as $field) {
52 $value = '';
53 if ($field === 'title') {
54 if (isset($params['row']['title'])) {
55 $fullTitle = $params['row']['title'];
56 } else {
57 try {
58 $metaDataRepository = GeneralUtility::makeInstance(MetaDataRepository::class);
59 $metaData = $metaDataRepository->findByFileUid($fileRecord['uid']);
60 $fullTitle = $metaData['title'];
61 } catch (InvalidUidException $e) {
62 /**
63 * We just catch the exception here
64 * Reasoning: There is nothing an editor or even admin could do
65 */
66 $fullTitle = '';
67 }
68 }
69
70 $value = BackendUtility::getRecordTitlePrep(htmlspecialchars($fullTitle));
71 } else {
72 if (isset($params['row'][$field])) {
73 $value = htmlspecialchars($params['row'][$field]);
74 } elseif (isset($fileRecord[$field])) {
75 $value = BackendUtility::getRecordTitlePrep($fileRecord[$field]);
76 }
77 }
78 if ((string)$value === '') {
79 continue;
80 }
81 $labelText = LocalizationUtility::translate('LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file.' . $field, 'lang');
82 $title[] = '<dt>' . htmlspecialchars($labelText) . '</dt>' . '<dd>' . $value . '</dd>';
83 }
84 $params['title'] = '<dl>' . implode('', $title) . '</dl>';
85 }
86 }