Unable to move media items due to overwritten rendered entity in the custom media library widget

Created on 2 March 2023, over 1 year ago
Updated 31 May 2024, 28 days ago

In the ContextualImageCropMediaLibraryWidget, the 'rendered_entity' from the original element is overwritten like so:

$element['selection'][$delta]['rendered_entity'] = [
'#media' => $media_item,
[
'#theme' => 'contextual_image_widget_crop_library_widget_thumbnail',
'#element_parents' => implode('/', $element_parents),
'#image' => [
'#theme' => 'image_style',
'#style_name' => $image_style->getName(),
'#uri' => $file->getFileUri(),
],
],
];

Can we document why this is necessary, and if not perhaps remove it? Is it to apply the cropping to the thumbnails in the widget?
On one of our sites, in combination with the Gin theme and some other customizations, this breaks the ability to move media items.

Commenting the above code solves the issue for me.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium RandalV

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

Comments & Activities

  • Issue created by @RandalV
  • πŸ‡§πŸ‡ͺBelgium svendecabooter Gent

    I think it is used for the refresh logic when the modal dialog is closed - see \Drupal\contextual_image_widget_crop\Form\MediaAjaxForm::ajaxCloseDialog().

    However, the code is also flawed, in that the $image_style variable is just the last one from the $image_styles array that could contain multiple image styles, so it just randomly picks the last one, from what I can tell.

    Will need some extra investigation.

Production build 0.69.0 2024