Image Media thumbnail alt text cannot be changed without reuploading the image

Created on 10 September 2021, over 3 years ago
Updated 20 January 2023, almost 2 years ago

Problem/Motivation

Media entities have base field definitions for a thumbnail, which includes alt text.

For media types that use an image as their source field, they are essentially pointing at the same thing.

For media types that use an image field as their base (like the default Image media type), the source field and thumbnail point to the same file, but attributes like alt are stored in two different database tables.

When alt text is updated for the source field (without also changing the image), the alt text does NOT get updated on the thumbnail. This is confusing as the any view or display that renders the thumbnail will be using the original alt text that was provided, where as views or displays that render the source field will use the correct alt text.

Here's why it happens:

Media module has a built in mechanism for triggering an update to the thumbnail, but it's only triggered if it thinks the source field has changed:

  protected function shouldUpdateThumbnail($is_new = FALSE) {
    // Update thumbnail if we don't have a thumbnail yet or when the source
    // field value changes.
    return !$this->get('thumbnail')->entity || $is_new || $this->hasSourceFieldChanged();
  }

  protected function hasSourceFieldChanged() {
    $source = $this->getSource();
    return isset($this->original) && $source->getSourceFieldValue($this) !== $source->getSourceFieldValue($this->original);
  }

For Image source fields, it only checks if the main property has changed, which in this case is the reference to the file entity. So, it would trigger a thumbnail update if the user uploaded a different image, but not if the alt text on the image was changed.

Unfortunately, I don't even think there is a workaround available to manually refresh the thumbnail data until Expose triggering update of media metadata + thumbnail to end users Needs work gets in.

Steps to reproduce

  1. Install Media module
  2. Add an Image media entity with any image file and specify alt text
  3. Edit the image media entity and update the alt text and save
  4. Observe that in the media table view listing, the thumbnail image alt text uses the original alt text

Proposed resolution

What if the we leave it up to source field plugins to determine if their source field has changed? Right now the Media entity class determines this on their behalf but that doesn't seem right. Individual source plugins know best about their sources and what constitutes a change.

Media module could expand hasSourceFieldChanged to ask the source if it's changed as well.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

10.1

Component
Media 

Last updated 41 minutes ago

Created by

🇺🇸United States bkosborne New Jersey, USA

Live updates comments and jobs are added and updated live.
  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024