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.

CommentFileSizeAuthor
#5 svg_issue.png74.41 KBtushar1
svg_image-php8-item-attributes.patch485 bytesgraker

Issue fork svg_image-3601247

Command icon 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

graker created an issue. See original summary.

f0ns’s picture

I just updated to Drupal 11.4 and I have the same issue,

The patch fixed the issue for me.

f0ns’s picture

Converted 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.

tushar1’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new74.41 KB

Tested 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.

anybody’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, merged!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • f0ns committed 9635d676 on 3.x
    Issue #3601247: Fix TypeError when #item_attributes is NULL in...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.