Bug #87784
closedClickEnlargeViewHelper causes error "Object of class FileReference could not be converted to string in TemplateService.php line 1441"
0%
Description
I just upgraded a website from v8 LTS to v9 LTS (9.5.4). On the new version, I am using fluid styled content. I have been using CSS styled content before.
I added the following lines to the page ts constants to use a lightbox script:
styles.content.textmedia.linkWrap {
lightboxEnabled = 1
width = 1024m
height = 768m
}
I added the following crop variants to page ts config:
TCEFORM.sys_file_reference.crop.config.cropVariants {
default {
title = Desktop
selectedRatio = NaN
allowedAspectRatios {
NaN {
title = Free
value = 0.0
}
21:9 {
title = 21:9
value = 2.3333333
}
16:9 {
title = 16:9
value = 1.7777777
}
4:3 {
title = 4:3
value = 1.3333333
}
3:2 {
title = 3:2
value = 1.5
}
1:1 {
title = 1:1
value = 1
}
}
}
og_image {
title = Open Graph Image
selectedRatio = 1:1
allowedAspectRatios {
1:1 {
title = 1:1
value = 1
}
}
}
header {
title = Header Image
selectedRatio = 31:01
allowedAspectRatios {
31:01 {
title = 31:10
value = 3.1
}
}
}
}
After adding these crop variants, I get the following error on rendering image content elements, which have the click enlarge check box enabled:
Core: Error handler (FE): PHP Catchable Fatal Error: Object of class TYPO3\CMS\Core\Resource\FileReference could not be converted to string in /home/some_path/www/typo3/sysext/core/Classes/TypoScript/TemplateService.php line 1441
I also added the stack trace.
Files
Updated by Adrian Dymorz over 5 years ago
When I replace
$theImage = $tsfe->tmpl->getFileName($file);
by
if ($file instanceof FileReference) { $fileAsString = $file->getForLocalProcessing(false); } else { $fileAsString = $file; } $theImage = $tsfe->tmpl->getFileName($fileAsString);
in typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php on line 5040 in the T3 v9 branch it works fine.
While working on a patch, I noticed, that the code there changed in master branch. I realized that my knowledge about TYPO3 is way to weak to write the change including the tests in a useful amount of time :-(
I hope I fulfilled my duty creating this issue.
Updated by Georg Ringer over 5 years ago
- Category deleted (
Fluid Styled Content) - Status changed from New to Needs Feedback
- Assignee deleted (
Benjamin Kott)
Sorry I don't find this code. can you point me to it in https://github.com/TYPO3/TYPO3.CMS/tree/9.5?
Updated by Adrian Dymorz over 5 years ago
Thanks for your answer.
I just upgraded to 9.5.5 a few minutes ago. The problem has gone. The images including click enlarge are rendered correctly.
The issue may be closed.
Updated by Georg Ringer over 5 years ago
- Status changed from Needs Feedback to Closed
Thx for feedback
Updated by Adrian Dymorz over 4 years ago
- TYPO3 Version changed from 9 to 10
- PHP Version changed from 7.2 to 7.4
Updated by Adrian Dymorz over 4 years ago
The issue is back :-(
I just upgraded from T3 9.x To 10.4.0 and the issues causes error messages again.
I replaced line 4436 in `www/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php`.
Old code:
$theImage = GeneralUtility::makeInstance(FilePathSanitizer::class)->sanitize((string)$file);
New code:
if ($file instanceof FileReference) {
$fileAsString = $file->getForLocalProcessing(false);
} else {
$fileAsString = $file;
}
$theImage = GeneralUtility::makeInstance(FilePathSanitizer::class)->sanitize((string)$fileAsString);
With this change, the error message is gone.
Updated by Jan Epper over 3 years ago
- Related to Bug #93345: Exception when image with 0 bytes is used for click enlarge added
Updated by Jennifer Hauß over 2 years ago
Maybe this will be helpful for some stumbling on this:
I ran into the same error in versoin 9.5.36 when trying to use an svg image with enlarge on click enabled.
The described fix above was working, but I wanted to know why the error occured as it didn't happen in another instance with the same TYPO3 version.
I discovered that svg wasn't included in $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] which resulted in the variable $imageResource not being set (see code below) in the if statement:
if (!isset($imageResource)) {
try {
$theImage = GeneralUtility::makeInstance(FilePathSanitizer::class)->sanitize((string)$file);
...
which comes right before the above stated problematic line.
By adding svg to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] I didn't ran into the issue anymore. This would apply to other file endings too, if missing in the setting.
This is pretty specific, but maybe it will help someone.
Updated by André Buchmann almost 2 years ago
Whe had this with a mp4 video which was used in the pages resourced. A seo extension tried to build og:image and twitter:image out of the mp4 file and failed with the same error. This was no issue with php 7.2 and only occured when we switched to 7.4