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.
Comments
Comment #2
feyp commentedAttached 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.
Comment #3
gnikolovskiComment #4
gnikolovskiFixed.
Thanks!