Stemming from #2303765-83: Make the default 'alt' attribute for Image fields required, if you have a thumbnail View of an image in a link, "that alt text should provide direction on what the link is, not necessarily describe the image."

How do we make this easier to build in Drupal 8? Certainly, it might be possible to find an easier way to pull in a title into the View.

Is there a way to make this more user friendly? How do we make this the default behaviour?

Original issue:

Many images in image fields, as opposed to those uploaded via wysiwyg - are used in multiple locations. Commonly this becomes a thumbnail, which is then linked through to the node it originated from.

When that image becomes a link - it MUST have alt text, and that alt text should provide direction on what the link is, not necessarily describe the image.

This was "solved", by instructing users to make the alt text the same as the title of the node, but that's not a great solution. We're also using a default image for some nodes. We considered adding a snippet of code to automatically copy the node title into the alt text field for the thumbnail in a view list. But that is also clunky.

The end result for users with screen readers is a stutter. The image link is right next to a title link, both of which repeat the title of the node. Which gets flagged as non-compliant by accessibility checkers :/

Comments

kattekrab’s picture

Issue summary: View changes
kattekrab’s picture

Copied in the text from the comment so I can follow up and track this.

I feel there has to be a better way, but I don't know what that way might be!

kattekrab’s picture

Version: 8.0.x-dev » 8.1.x-dev

Bumping this to 8.1 though.

dawehner’s picture

What about also somehow include the field label, would that improve the situation?

mgifford’s picture

@dawehner where would you put the field label? Ultimately we need to be able to add alt text with a view and provide flexibility such that it isn't necessarily the alt text associated with the uploaded image.

dawehner’s picture

What we could do:

  • Expand image-formatter.html.twig to also allow some {{ desciption }}
  • In core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php we then pass along the entity label as additional description
  • Profit, and a three points list
mgifford’s picture

Version: 8.1.x-dev » 8.0.x-dev

Ok, that sounds like a plan. I'm hopeful in that we can nudge this back to the 8.0 release rather than the 8.1, but if we don't get a patch for this soon, obviously it wasn't meant to be.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

tgoeg’s picture

What is the current best practice/workaround to get this fixed in the meantime? Not being able to use images as links altogether just because of a11y incompatibility is pretty cumbersome.

After searching high and low and fiddling with it, I use a link override like this now

{% autoescape false %}
{{ field_image|replace({'alt': 'alt=\"' ~ title ~ '\" image-description' }) }}
{% endautoescape %}

i.e. in lack of a regex search/replace I use the tag as an anchor, assign the old value of alt to some unused attribute like image-description and set alt={{ title }} (of the content I want to link to) instead.

Just using replace makes the view put out escaped ankle brackets. I am a twig-noob, so maybe there is some drawback to doing it like this or there is some other magic incantation to stop that from happening?
field_image|raw|replace does not seem to work, either.

One really easy solution (I think, and the place I would have expected it most) would be to offer a field for alt alongside the other (Link class, Title text, Rel Text ..) below "Output this field as a custom link". Everyone could override it with whatever they see fit. If it supports twig and variable replacement, that is.

Considering that this ticket is 7 years old, some kind of official intermediate solution/how to/documentation should be provided. Maybe with the method I outline above.
Fixing it would also be a solution (but as I am not a dev I don't want to sound pushy but try to provide a workaround at least) :-)

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.