Problem/Motivation
I use 3.2.2 version of the module with Drupal 11.4. PHP version is 8.3. I have added media reference fields to some nodetypes, now when I try to see Media library or add a Media reference to a node, I see ajax error that is caused by this in the log:
> TypeError: Unsupported operand types: null + array in Drupal\svg_image\Plugin\Field\FieldFormatter\SvgImageFormatter->renderAsImg() (line 130 of /var/www/html/web/modules/contrib/svg_image/src/Plugin/Field/FieldFormatter/SvgImageFormatterTrait.php).
Proposed resolution
Attaching a patch that would assume default for item_attributes.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | svg_issue.png | 74.41 KB | tushar1 |
| svg_image-php8-item-attributes.patch | 485 bytes | graker |
Issue fork svg_image-3601247
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
f0ns commentedI just updated to Drupal 11.4 and I have the same issue,
The patch fixed the issue for me.
Comment #4
f0ns commentedConverted the patch to an MR against 3.x, same fix as graker's patch.
I'll leave it in Needs review to have a fresh pair of eyes on it.
Comment #5
tushar1 commentedTested on:
Drupal 11.4.0
PHP 8.3
SVG Image 3.2.3
I was able to reproduce the issue before applying the proposed patch.
Steps performed to reproduce
Installed and enabled the svg_image module.
Enabled the Media and Media Library modules.
Configured the Image media type to allow SVG uploads.
Created an SVG media item by uploading an SVG file.
Created a Media reference field (Image media type) on the Article content type.
Attempted to create/save the SVG media item.
Result before applying the patch:
The media save operation failed with the reported error:
TypeError: Unsupported operand types: null + array
in SvgImageFormatterTrait::renderAsImg().
Patch verification
Applied the proposed patch from the issue and rebuilt caches.
Regression testing performed
Verified SVG media can be created successfully.
Verified SVG media can be edited successfully.
Created an Article with a Media reference field.
Added the SVG media through the Media Library.
Successfully saved the Article.
Verified the SVG renders correctly on the Article page.
Cleared Drupal caches and re-tested.
Checked Recent log messages and observed no related PHP errors.
Result after applying the patch
The reported TypeError is resolved, SVG media can be created and referenced successfully, and I did not observe any regressions during testing.
Moving to RTBC.
Comment #6
anybodyThanks, merged!