TYPO3 CMS  TYPO3_7-6
UserFileInlineLabelService.php
Go to the documentation of this file.
1 <?php
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 
20 
25 {
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  : [];
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 = [];
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) {
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 }
static translate($key, $extensionName, $arguments=null)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static getRecordTitlePrep($title, $titleLength=0)
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)