Problem/Motivation

We're getting this exception for some formatter configurations on PHP 8.1:

Deprecated function: DOMElement::setAttribute(): Passing null to parameter #2 ($value) of type string is deprecated in Drupal\svg_formatter\Plugin\Field\FieldFormatter\SvgFormatter->viewElements()

Steps to reproduce

In the formatter settings, check "Output SVG inline" and "Set image dimensions." and set a width and/or height.

inline is false by default, but the default value for apply_dimensions is TRUE and the width and height are integer 100 by default, so this should be visible as soon as you enable inline.

Proposed resolution

Cast the values to string.

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#2 3390421-02.patch1.67 KBfeyp

Comments

FeyP created an issue. See original summary.

feyp’s picture

Assigned: feyp » Unassigned
Status: Active » Needs review
StatusFileSize
new1.67 KB

Attached is a patch against 2.0.x-dev/2.0.2.

Note that the patch adds filtering of the attribute value based on \Drupal\Core\Template\AttributeString::__toString(), only using Html::escape() directly since it was already used anyway, and a check, if the value is not empty. Technically, the first hunk of the patch should be enough to fix the bug.

gnikolovski’s picture

Assigned: Unassigned » gnikolovski
gnikolovski’s picture

Status: Needs review » Fixed

Fixed.

Thanks!

  • gnikolovski committed d588b5ff on 2.0.x authored by FeyP
    Issue #3390421 by FeyP, gnikolovski: DOMElement::setAttribute(): Passing...

Status: Fixed » Closed (fixed)

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