diff --git a/typo3/sysext/core/Classes/Resource/Service/UserFileInlineLabelService.php b/typo3/sysext/core/Classes/Resource/Service/UserFileInlineLabelService.php index 9d2c30757a434551fa269d29af5d6bc7cfcea032..ab53b4550cf825065a17728a0b319c0d242459c4 100644 --- a/typo3/sysext/core/Classes/Resource/Service/UserFileInlineLabelService.php +++ b/typo3/sysext/core/Classes/Resource/Service/UserFileInlineLabelService.php @@ -17,10 +17,10 @@ namespace TYPO3\CMS\Core\Resource\Service; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; +use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Resource\Exception\InvalidUidException; use TYPO3\CMS\Core\Resource\Index\MetaDataRepository; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Utility\LocalizationUtility; /** * User file inline label service @@ -54,49 +54,71 @@ class UserFileInlineLabelService } // Configuration - $title = ''; - foreach ($sysFileFields as $field) { - $value = ''; - if ($field === 'title') { - if (isset($params['row']['title'])) { - $fullTitle = $params['row']['title']; - } else { - try { - $metaDataRepository = GeneralUtility::makeInstance(MetaDataRepository::class); - $metaData = $metaDataRepository->findByFileUid($fileRecord['uid']); - $fullTitle = $metaData['title'] ?? ''; - } catch (InvalidUidException $e) { - /** - * We just catch the exception here - * Reasoning: There is nothing an editor or even admin could do - */ - $fullTitle = ''; - } - } - - $value = BackendUtility::getRecordTitlePrep($fullTitle); - } else { - if (isset($params['row'][$field])) { - $value = htmlspecialchars($params['row'][$field]); - } elseif (isset($fileRecord[$field])) { - $value = BackendUtility::getRecordTitlePrep($fileRecord[$field]); - } - } - if ((string)$value === '') { - continue; - } - $labelText = (string)LocalizationUtility::translate('LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_file.' . $field); - $title = '<dt class="col text-truncate">' . htmlspecialchars($labelText) . '</dt><dd class="col">' . $value . '</dd>'; - // In debug mode, add the table name to the record title - if ($this->getBackendUserAuthentication()->shallDisplayDebugInformation()) { - $title .= '<div class="col"><code class="m-0">[' . htmlspecialchars($params['table']) . ']</code></div>'; + $value = ''; + $recordTitle = $this->getTitleForRecord($params['row'], $fileRecord); + $recordName = $this->getLabelFieldForRecord($params['row'], $fileRecord, 'name'); + + $labelField = !empty($recordTitle) ? 'title' : 'name'; + + if (!empty($recordTitle)) { + $value .= $recordTitle . ' (' . $recordName . ')'; + } else { + $value .= $recordName; + } + + $title = ' + <dt class="col-1"> + ' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_file.' . $labelField)) . ' + </dt> + <dd class="col text-truncate"> + ' . $value . ' + </dd> + <div class="w-100"></div>'; + + // In debug mode, add the table name to the record title + if ($this->getBackendUserAuthentication()->shallDisplayDebugInformation()) { + $title .= '<div class="col"><code class="m-0">[' . htmlspecialchars($params['table']) . ']</code></div>'; + } + + $params['title'] = '<dl class="row row-cols-auto">' . $title . '</dl>'; + } + + protected function getTitleForRecord(array $databaseRow, array $fileRecord): string + { + $fullTitle = ''; + if (isset($databaseRow['title'])) { + $fullTitle = $databaseRow['title']; + } else { + try { + $metaDataRepository = GeneralUtility::makeInstance(MetaDataRepository::class); + $metaData = $metaDataRepository->findByFileUid($fileRecord['uid']); + $fullTitle = $metaData['title'] ?? ''; + } catch (InvalidUidException $e) { } } - $params['title'] = '<dl class="row row-cols-auto g-2">' . $title . '</dl>'; + + return BackendUtility::getRecordTitlePrep($fullTitle); + } + + protected function getLabelFieldForRecord(array $databaseRow, array $fileRecord, string $field): string + { + $value = ''; + if (isset($databaseRow[$field])) { + $value = htmlspecialchars($databaseRow[$field]); + } elseif (isset($fileRecord[$field])) { + $value = BackendUtility::getRecordTitlePrep($fileRecord[$field]); + } + + return $value; } protected function getBackendUserAuthentication(): BackendUserAuthentication { return $GLOBALS['BE_USER']; } + + protected function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } }