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

Created on 26 March 2024, 3 months ago
Updated 2 April 2024, 3 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
  • πŸ‡©πŸ‡ͺGermany sreher
  • Status changed to Postponed: needs info 3 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.69.0 2024