Formatter errors because width and height are not always set

Created on 11 March 2025, 6 months ago

Problem/Motivation

When using the svg_image formatter in forms, the width and height are not always available and cause an error.
Warning: Undefined array key "width" in Drupal\svg_image\Plugin\Field\FieldFormatter\SvgImageFormatter->svgSettingsForm() (line 57 of modules/contrib/svg_image/src/Plugin/Field/FieldFormatter/SvgImageFormatterTrait.php).

Proposed resolution

See fix:

Remaining tasks

Review

🐛 Bug report
Status

Active

Version

3.2

Component

Code

Created by

🇳🇱Netherlands johankleene Helmond

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @johankleene
  • 🇳🇱Netherlands johankleene Helmond
  • 🇮🇳India shivam_tiwari

    I checked this, but not getting any issue like this. Can you please provide here steps to reproduce of this issue?

  • 🇮🇳India abhijeetsatpute

    I was able to reproduce this issue on a Drupal 11 site using SVG Image 3.2.1.

    The error occurs when switching the field formatter to Image (provided by svg_image → \src\Plugin\Field\FieldFormatter\SvgImageFormatter.php).

    When checking the formatter configuration, I see the following:

    Array
    (
      [image_style] => convert_to_avif
      [svg_attributes] => 
      [svg_render_as_image] => 1
      [image_link] => 
      [image_loading] => Array ( [attribute] => lazy )
    )
    
    

    Here svg_attributes is stored as an empty string, which leads to the error when accessed as an array.
    The commit available in the issue branch resolves the problem.

  • 🇮🇳India sivaprasadc

    sivaprasadc changed the visibility of the branch 3512208-formatter-errors-because to hidden.

Production build 0.71.5 2024