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 #2983456: Expose triggering update of media metadata + thumbnail to end users gets in.
Steps to reproduce
- Install Media module
- Add an Image media entity with any image file and specify alt text
- Edit the image media entity and update the alt text and save
- 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.