[BUGFIX] FAL: Fix inline labels for fields of type group
[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\Utility\GeneralUtility;
19 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
20
21 /**
22 * User file inline label service
23 */
24 class UserFileInlineLabelService
25 {
26 /**
27 * Get the user function label for the file_reference table
28 *
29 * @param array $params
30 * @return void
31 */
32 public function getInlineLabel(array &$params)
33 {
34 $sysFileFields = isset($params['options']['sys_file']) && is_array($params['options']['sys_file'])
35 ? $params['options']['sys_file']
36 : array();
37
38 if (empty($sysFileFields)) {
39 // Nothing to do
40 $params['title'] = $params['row']['uid'];
41 return;
42 }
43
44 // In case of a group field uid_local has the table_uid|label syntax
45 $tableAndUid = array_shift(GeneralUtility::trimExplode('|', $params['row']['uid_local'], true, 2));
46 $fileInfo = BackendUtility::splitTable_Uid($tableAndUid);
47 $fileRecord = BackendUtility::getRecord($fileInfo[0], $fileInfo[1]);
48
49 // Configuration
50 $title = array();
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(\TYPO3\CMS\Core\Resource\Index\MetaDataRepository::class);
59 $metaData = $metaDataRepository->findByFileUid($fileRecord['uid']);
60 $fullTitle = $metaData['title'];
61 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidUidException $e) {
62 /**
63 * We just catch the exception here
64 * Reasoning: There is nothing an editor or even admin could do
65 */
66 }
67 }
68
69 $value = BackendUtility::getRecordTitlePrep(htmlspecialchars($fullTitle));
70 } else {
71 if (isset($params['row'][$field])) {
72 $value = htmlspecialchars($params['row'][$field]);
73 } elseif (isset($fileRecord[$field])) {
74 $value = BackendUtility::getRecordTitlePrep($fileRecord[$field]);
75 }
76 }
77 if ((string)$value === '') {
78 continue;
79 }
80 $labelText = LocalizationUtility::translate('LLL:EXT:lang/locallang_tca.xlf:sys_file.' . $field, 'lang');
81 $title[] = '<dt>' . htmlspecialchars($labelText) . '</dt>' . '<dd>' . $value . '</dd>';
82 }
83 $params['title'] = '<dl>' . implode('', $title) . '</dl>';
84 }
85 }