Problem/Motivation
Media::prepareSave() may regenerate the thumbnail even when a thumbnail value already exists on the entity.
Steps to reproduce
- Create a Media entity.
- Set a custom value in thumbnail.
- (Optional) Allow editing thumbnail via form:
/** * Implements hook_entity_base_field_info_alter(). */ function my_module_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) { if ($entity_type->id() == 'media') { // Allow uploading or removing the thumbnail image. $fields['thumbnail']->setDisplayConfigurable('form', TRUE); } } - Save the entity.
- Edit and save again without changing thumbnail.
- Thumbnail may be regenerated and overwritten.
Proposed resolution
Do not regenerate thumbnail when a thumbnail already exists. Change condition in prepareSave():
// Set thumbnail.
if (
$this->isNew()
&& $translation->get('thumbnail')->isEmpty()
&& $translation->shouldUpdateThumbnail(TRUE)
) {
$translation->updateThumbnail();
}
Remaining tasks
Review condition.
User interface changes
None.
Introduced terminology
None.
API changes
Media::prepareSave() will no longer regenerate thumbnails on update when a thumbnail value already exists.
Thumbnail generation is limited to new entities or cases where the thumbnail field is empty.
Data model changes
None.
Release notes snippet
Media no longer regenerates thumbnails on updates when a thumbnail already exists. Thumbnail generation now only occurs for new entities or when the thumbnail field is empty.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | issue-3608686.patch | 625 bytes | paweldxm |
Issue fork drupal-3608686
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
paweldxm commentedComment #3
smustgrave commentedThink this was put in backport by accident?