Skip to content
Snippets Groups Projects
Commit 37ea5a51 authored by Nikita Hovratov's avatar Nikita Hovratov
Browse files

[BUGFIX] Fix label generation for inline files

The labels of inline FileReference fields were not concatenated
but overwritten, in a loop since #92427.

This patch corrects the concatenation and adds line-break divs,
otherwise the strings are on a single line.

Resolves: #99873
Related: #92427
Releases: main, 12.4, 11.5
Change-Id: I368cd0d2cbf7e9ed7fdd1d003f869cc894d6f13e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80265


Tested-by: default avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: default avatarNikita Hovratov <nikita.h@live.de>
Tested-by: default avatarcore-ci <typo3@b13.com>
parent dccecc5b
Branches
Tags
No related merge requests found
......@@ -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'];
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment