#106554Localized images (media files) of sys_file_reference is not translated in frontend
Description
Prerequisites
I have setup a clean environment to reproduce the issue.
PHP 8.3 / 8.4
TYPO3 13.4.9 (composer based)
Setup at least 2 languages with strict fallback (0 = EN, 1 = DE).
Content rendering done with PAGEVIEW cObject + ContentBlocks
A partial solution was done in https://forge.typo3.org/issues/106303
Steps to reproduce:
1. Create Text & Media with image_1 (sys_file_reference) attached on default language [EN]
2. Translate Text & Media to DE language and change image_1 to image_2 (diffrent image). New sys_file_reference does not have l10_parent value.
3. On the frontend of DE language: the image is missing as localized image_2 was not found.
Expected result
Have the possibility to set different images(media) for translated content and keep Strict fallback mode for DE lang.
Basic user case: image with the EN text and for translated DE page it should be image with DE text
Rendering with CONTENT cObject still works properly
In case Content cObject is used to render elements by colPos -> the DE Text & Media is rendered properly with localized image_2 ( file reference l10_parent = 0)
While the records fething the tt_content records is overlayed and _LOCALIZED_UID property is attached to record data array. See:
\TYPO3\CMS\Frontend\ContentObject\ContentContentObject::render \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::getRecords \TYPO3\CMS\Core\Domain\Repository\PageRepository::getLanguageOverlay
Issue / Problem
According to PAGEVIEW content rendering is done via “page-content” data processor
While debugging “page-content” data processor: the result (RawRecord) is correct. The correct localized sys_file_reference is properly found (image_2)
Then, according to docs: Resources/PageView/Default/Default.html
<f:for each="{content.main.records}" as="record">
<f:cObject typoscriptObjectPath="{record.mainType}" table="{record.mainType}" data="{record}"/>
</f:for>
Next \TYPO3\CMS\Fluid\ViewHelpers\CObjectViewHelper::render handles content elements rendering, and that’s why the issue appears
vendor/typo3/cms-fluid/Classes/ViewHelpers/CObjectViewHelper.php:86
$data = $data instanceof RecordInterface ? ($data->getRawRecord()?->toArray() ?? $data->toArray()) : ObjectAccess::getGettableProperties($data);
$data->getRawRecord()?->toArray() return record array with “_computed” property where “localizedUid” is stored but NOT “_LOCALIZED_UID” property in the record data array.
….. some processing and it gets to “files” data processor
\TYPO3\CMS\Frontend\Resource\FileCollector::addFilesFromRelation \TYPO3\CMS\Frontend\Resource\FileCollector::getFileReferences
as “_LOCALIZED_UID” is not presented the localized fileReference not found
$localizedId = $element['_LOCALIZED_UID'] ?? null;
$isTableLocalizable = (
!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
&& !empty($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
);
if ($isTableLocalizable && $localizedId !== null) {
....
As a result on frontend: image_2 (sys_file_reference) is not found and missing.
1st Solution
Add _LOCALIZED_UID value in RawRecord model for further proper usage in \TYPO3\CMS\Frontend\Resource\FileCollector::getFileReferences
vendor/typo3/cms-core/Classes/Domain/RawRecord.php:73
$properties += ['uid' => $this->uid, 'pid' => $this->pid, '_LOCALIZED_UID' => $this->getComputedProperties()->getLocalizedUid()];
2nd Solution
Respect/use new “record -> _computed -> localizedUid” value in \TYPO3\CMS\Frontend\Resource\FileCollector::getFileReferences for the proper localized file reference(s) fetching.