Project

General

Profile

Actions

Bug #101810

closed

ContentObjectRenderer::getImgResource() ignores cropping settings when passing a FileReference

Added by Kevin Meier 9 months ago. Updated 8 months ago.

Status:
Resolved
Priority:
Should have
Assignee:
-
Category:
Frontend
Start date:
2023-08-31
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
12
PHP Version:
8.1
Tags:
Complexity:
no-brainer
Is Regression:
Yes
Sprint Focus:

Description

When passing a FileReference object to the ContentObjectRenderer::getImgResource() function, the check for the FileReference fails when adding the cropping settings. From what I saw in the code, this should happen in TYPO3 11 and TYPO3 12 (tested in TYPO3 12) as well as the main branch. The failing check for TYPO3 12.4 can be found under https://github.com/TYPO3-CMS/frontend/blob/12.4/Classes/ContentObject/ContentObjectRenderer.php#L3791
This happens because $fileReference doesn't get set in the case of the first function parameter being a FileReference object. For a fix, instead of

if (isset($fileReference)) {
$processingConfiguration['crop'] = $this->getCropAreaFromFileReference($fileReference, $fileArray);
}

You could do

if (isset($fileReference) || $file instanceof FileReference) {
$processingConfiguration['crop'] = $this->getCropAreaFromFileReference($fileReference ?? $file, $fileArray);
}

I don't know if that's clean code, just a basic idea. Also I don't know how to create patches but feel free to do so.

Actions

Also available in: Atom PDF