When translating a media file entity, the thumbnail of the original entity is deleted.

Created on 26 March 2024, 8 months ago
Updated 2 April 2024, 8 months ago

Problem/Motivation

When deleting a media item, the thumbnail of the original entity gets deleted.

Steps to reproduce

Install a standard Drupal site and enable the Media module
Enable the media, the media_thumbnails and the media_thumbnails_pdf module
Upload a media file, ex. a pdf file, see that a thumbnail will be generated
Translate the media file to an other language, see that the thumbnail will be generated
Visit the original media entity and see that this thumbnail is missing.

Proposed resolution

Prevent the deletion of the thumbnail in the file `media_thumbnails/src/Plugin/MediaThumbnailManager.php` and the deleteThumbnail(...) function.

    // Don't delete thumbnail from the original media entity.
    // If there is a translation, do not delete the thumbnail on the original media entity
    // When a translation is deleted, do not delete the thumbnail on the original media entity
    $routeName = \Drupal::request()->attributes->get('_route');
    if (
      ($routeName !== 'entity.media.delete_form' && count($media->getTranslationLanguages()) > 1)
    ) {
      return;
    }

Remaining tasks

Can you verify my observations and test if the propose solution works in all cases.

🐛 Bug report
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

🇩🇪Germany sreher

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @sreher
  • Status changed to Postponed: needs info 8 months ago
  • 🇩🇪Germany drubb Sindelfingen

    Hey Sven,

    just to clarify:

    The attached PDF in the translation is the same file as in the original? Or is it a translated file, with a different name?

  • 🇩🇪Germany sreher

    Hey Boris,
    it is the same file.

  • 🇩🇪Germany sreher

    I make the code more robust.

  • 🇩🇪Germany drubb Sindelfingen

    I'll need to take a closer look, but for now:

    We'll need to handle all ways of deletion, not just manual ones (using the form).
    When deleting any translation (or the origin), we need to load all existing translations and check
    if the file id of the thumbnail is used in any other translation - in this case, the
    file must not be deleted. This would be the case, if a media file (and thus its thumbnail)
    is reused in multiple translations.

Production build 0.71.5 2024