Use aria-label for 'Enable alt attribute' when 'Output SVG Inline' is enabled

Created on 30 March 2023, about 1 year ago
Updated 11 September 2023, 10 months ago

Problem/Motivation

Currently, when using the SVG Image Field module and the "Output SVG inline" option is enabled, the "Alt" attribute is not printed in the output. This causes an accessibility issue as assistive technologies need alternative text for images so that the user will know what that is.

Note: the "Alt" attribute is properly rendered as part of the <img> tag when the "Output SVG inline" option is disabled.

Steps to reproduce

  1. Install a new Drupal site using the standard installation profile
  2. Enable the svg_image_field module
  3. Add an 'SVG Image' field to the basic page node bundle.
  4. At the 'Manage display' tab, choose the 'SVG Image Field formatter' and enable 'Output SVG inline' and 'Enable alt attribute' options.
  5. Create a new basic page node with an SVG image, and fill out its Alt field.
  6. Notice that on the newly created node's view page, the rendered <svg> tag does not contain the value entered in its Alt field.

Proposed resolution

Print the Alt field's value as an aria-label attribute of the inline <svg> tag.

Remaining tasks

Modify the viewElements() method of SvgImageFieldFormatter class so the aria-label attribute is set on the <svg> tag.

User interface changes

None.

API changes

None.

Data model changes

None.

✨ Feature request
Status

Postponed: needs info

Version

2.2

Component

Code

Created by

πŸ‡­πŸ‡ΊHungary zserno

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

Comments & Activities

Production build 0.69.0 2024