Context
When using a fileupload field to receive an SVG file, PrestaShop logs a PHP warning each time the block schema is hydrated for the BO panel:
Warning: Cannot use bool as array in
modules/prettyblocks/classes/prettyblocks/core/FieldCore.php on line 465
In dev environments with display_errors = 1, this warning is visible in the BO and pollutes the interface. In production with display_errors = 0, it goes to the error log but spams it on every BO refresh.
Root cause
FieldCore.php, around lines 449–475, in the method that formats a fileupload field value, contains:
if (!empty($value['url'])) {
$path = \HelperBuilder::pathFormattedFromUrl($value['url']);
if (file_exists($path)) {
$size = filesize($path);
if ($value['mediatype'] == 'image') {
list($width, $height) = getimagesize($path);
}
}
}
getimagesize() is a PHP function intended for raster images (PNG / JPG / GIF / WebP / etc.). For an SVG file (which PrettyBlocks correctly detects as mediatype = 'image' because SVG is image/svg+xml), getimagesize() returns false. The subsequent list(...) = false triggers the "Cannot use bool as array" warning in PHP 7.x and PHP 8.x.
Steps to reproduce
- Declare a custom block with a
fileupload field in a third-party module:
'icon' => [
'type' => 'fileupload',
'label' => 'Icon (SVG)',
'path' => '$/modules/yourmodule/views/images/',
'default' => ['url' => ''],
],
- In the BO, upload any
.svg file (e.g. a Lucide or Heroicons icon).
- Save and re-open the block configuration in the BO.
- Observe the PHP warning in display_errors / error log.
Suggested fix
Defensive check before destructuring the getimagesize() return value:
if ($value['mediatype'] == 'image') {
$imageSize = @getimagesize($path);
if (is_array($imageSize)) {
list($width, $height) = $imageSize;
}
}
The is_array guard handles SVG (and any other case where getimagesize fails) without spamming warnings. SVG files won't expose width / height via this code path — but that's expected behavior since SVG is vector and doesn't have intrinsic pixel dimensions in the same way. They can be parsed separately if needed (e.g. via simplexml_load_file to read the viewBox attribute), but a simple skip is a reasonable default.
Why it matters
SVG uploads are a common use case for custom blocks (icons in reassurance bandeau, badges, decorative elements). Third-party module developers should be able to use fileupload for SVG without polluting logs on every BO refresh.
Willing to contribute
Happy to open a PR with the fix above. Let me know if you'd prefer a different defensive style (e.g. early return, ?: null coalescing, etc.) or if SVG-specific handling (reading viewBox for natural dimensions) is desired alongside.
Context
When using a
fileuploadfield to receive an SVG file, PrestaShop logs a PHP warning each time the block schema is hydrated for the BO panel:In dev environments with
display_errors = 1, this warning is visible in the BO and pollutes the interface. In production withdisplay_errors = 0, it goes to the error log but spams it on every BO refresh.Root cause
FieldCore.php, around lines 449–475, in the method that formats afileuploadfield value, contains:getimagesize()is a PHP function intended for raster images (PNG / JPG / GIF / WebP / etc.). For an SVG file (which PrettyBlocks correctly detects asmediatype = 'image'because SVG isimage/svg+xml),getimagesize()returnsfalse. The subsequentlist(...) = falsetriggers the "Cannot use bool as array" warning in PHP 7.x and PHP 8.x.Steps to reproduce
fileuploadfield in a third-party module:.svgfile (e.g. a Lucide or Heroicons icon).Suggested fix
Defensive check before destructuring the
getimagesize()return value:The
is_arrayguard handles SVG (and any other case wheregetimagesizefails) without spamming warnings. SVG files won't exposewidth/heightvia this code path — but that's expected behavior since SVG is vector and doesn't have intrinsic pixel dimensions in the same way. They can be parsed separately if needed (e.g. viasimplexml_load_fileto read theviewBoxattribute), but a simple skip is a reasonable default.Why it matters
SVG uploads are a common use case for custom blocks (icons in reassurance bandeau, badges, decorative elements). Third-party module developers should be able to use
fileuploadfor SVG without polluting logs on every BO refresh.Willing to contribute
Happy to open a PR with the fix above. Let me know if you'd prefer a different defensive style (e.g. early return,
?:null coalescing, etc.) or if SVG-specific handling (readingviewBoxfor natural dimensions) is desired alongside.