Problem/Motivation

Media::prepareSave() may regenerate the thumbnail even when a thumbnail value already exists on the entity.

Steps to reproduce

  1. Create a Media entity.
  2. Set a custom value in thumbnail.
  3. (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);
       }
     }
     
  4. Save the entity.
  5. Edit and save again without changing thumbnail.
  6. 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.

CommentFileSizeAuthor
#2 issue-3608686.patch625 bytespaweldxm

Issue fork drupal-3608686

Command icon 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

paweldxm created an issue. See original summary.

paweldxm’s picture

StatusFileSize
new625 bytes
smustgrave’s picture

Version: 10.6.x-dev » main
Status: Patch (to be ported) » Active

Think this was put in backport by accident?