‪TYPO3CMS  11.5
UserFileInlineLabelService.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
24 
29 {
35  public function ‪getInlineLabel(array &$params)
36  {
37  $sysFileFields = isset($params['options']['sys_file']) && is_array($params['options']['sys_file'])
38  ? $params['options']['sys_file']
39  : [];
40 
41  if (empty($sysFileFields)) {
42  // Nothing to do
43  $params['title'] = $params['row']['uid'];
44  return;
45  }
46 
47  // In case of a group field uid_local is a resolved array
48  $fileRecord = $params['row']['uid_local'][0]['row'] ?? null;
49 
50  if ($fileRecord === null) {
51  // no file record so nothing more to do
52  $params['title'] = $params['row']['uid'];
53  return;
54  }
55 
56  // Configuration
57  $value = '';
58  $recordTitle = $this->‪getTitleForRecord($params['row'], $fileRecord);
59  $recordName = $this->‪getLabelFieldForRecord($params['row'], $fileRecord, 'name');
60 
61  $labelField = !empty($recordTitle) ? 'title' : 'name';
62 
63  if (!empty($recordTitle)) {
64  $value .= $recordTitle . ' (' . $recordName . ')';
65  } else {
66  $value .= $recordName;
67  }
68 
69  $title = '
70  <dt class="col-1">
71  ' . htmlspecialchars($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_file.' . $labelField)) . '
72  </dt>
73  <dd class="col text-truncate">
74  ' . $value . '
75  </dd>
76  <div class="w-100"></div>';
77 
78  // In debug mode, add the table name to the record title
79  if ($this->‪getBackendUserAuthentication()->shallDisplayDebugInformation()) {
80  $title .= '<div class="col"><code class="m-0">[' . htmlspecialchars($params['table']) . ']</code></div>';
81  }
82 
83  $params['title'] = '<dl class="row row-cols-auto">' . $title . '</dl>';
84  }
85 
86  protected function ‪getTitleForRecord(array $databaseRow, array $fileRecord): string
87  {
88  $fullTitle = '';
89  if (isset($databaseRow['title'])) {
90  $fullTitle = $databaseRow['title'];
91  } else {
92  try {
93  $metaDataRepository = GeneralUtility::makeInstance(MetaDataRepository::class);
94  $metaData = $metaDataRepository->findByFileUid($fileRecord['uid']);
95  $fullTitle = $metaData['title'] ?? '';
96  } catch (‪InvalidUidException $e) {
97  }
98  }
99 
100  return BackendUtility::getRecordTitlePrep($fullTitle);
101  }
102 
103  protected function ‪getLabelFieldForRecord(array $databaseRow, array $fileRecord, string $field): string
104  {
105  $value = '';
106  if (isset($databaseRow[$field])) {
107  $value = htmlspecialchars($databaseRow[$field]);
108  } elseif (isset($fileRecord[$field])) {
109  $value = BackendUtility::getRecordTitlePrep($fileRecord[$field]);
110  }
111 
112  return $value;
113  }
114 
116  {
117  return ‪$GLOBALS['BE_USER'];
118  }
119 
121  {
122  return ‪$GLOBALS['LANG'];
123  }
124 }
‪TYPO3\CMS\Core\Resource\Index\MetaDataRepository
Definition: MetaDataRepository.php:41
‪TYPO3\CMS\Core\Resource\Service\UserFileInlineLabelService\getTitleForRecord
‪getTitleForRecord(array $databaseRow, array $fileRecord)
Definition: UserFileInlineLabelService.php:86
‪TYPO3\CMS\Core\Resource\Service\UserFileInlineLabelService\getLabelFieldForRecord
‪getLabelFieldForRecord(array $databaseRow, array $fileRecord, string $field)
Definition: UserFileInlineLabelService.php:103
‪TYPO3\CMS\Core\Resource\Exception\InvalidUidException
Definition: InvalidUidException.php:23
‪TYPO3\CMS\Core\Resource\Service
Definition: ConfigurationService.php:18
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Resource\Service\UserFileInlineLabelService
Definition: UserFileInlineLabelService.php:29
‪TYPO3\CMS\Core\Resource\Service\UserFileInlineLabelService\getInlineLabel
‪getInlineLabel(array &$params)
Definition: UserFileInlineLabelService.php:35
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Resource\Service\UserFileInlineLabelService\getLanguageService
‪getLanguageService()
Definition: UserFileInlineLabelService.php:120
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Resource\Service\UserFileInlineLabelService\getBackendUserAuthentication
‪getBackendUserAuthentication()
Definition: UserFileInlineLabelService.php:115