TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
UserFileInlineLabelService.php
Go to the documentation of this file.
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 
22 
27 {
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 has the table_uid|label syntax
47  $tableAndUid = array_shift(GeneralUtility::trimExplode('|', $params['row']['uid_local'], true, 2));
48  $fileInfo = BackendUtility::splitTable_Uid($tableAndUid);
49  $fileRecord = BackendUtility::getRecord($fileInfo[0], $fileInfo[1]);
50 
51  // Configuration
52  $title = [];
53  foreach ($sysFileFields as $field) {
54  $value = '';
55  if ($field === 'title') {
56  if (isset($params['row']['title'])) {
57  $fullTitle = $params['row']['title'];
58  } else {
59  try {
60  $metaDataRepository = GeneralUtility::makeInstance(MetaDataRepository::class);
61  $metaData = $metaDataRepository->findByFileUid($fileRecord['uid']);
62  $fullTitle = $metaData['title'];
63  } catch (InvalidUidException $e) {
68  $fullTitle = '';
69  }
70  }
71 
72  $value = BackendUtility::getRecordTitlePrep(htmlspecialchars($fullTitle));
73  } else {
74  if (isset($params['row'][$field])) {
75  $value = htmlspecialchars($params['row'][$field]);
76  } elseif (isset($fileRecord[$field])) {
77  $value = BackendUtility::getRecordTitlePrep($fileRecord[$field]);
78  }
79  }
80  if ((string)$value === '') {
81  continue;
82  }
83  $labelText = LocalizationUtility::translate('LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file.' . $field, 'lang');
84  $title[] = '<dt>' . htmlspecialchars($labelText) . '</dt>' . '<dd>' . $value . '</dd>';
85  }
86  $params['title'] = '<dl>' . implode('', $title) . '</dl>';
87  }
88 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static getRecord($table, $uid, $fields= '*', $where= '', $useDeleteClause=true)
static translate($key, $extensionName, $arguments=null)
static makeInstance($className,...$constructorArguments)