Re-sizing breaks after initial save or preview

Created on 30 October 2024, about 2 months ago

Problem/Motivation

Re-sizing works when media is first inserted, however, after saving or previewing the media image cannot be resized properly. The width could be increased, but the height doesn't adjust. Also the image doesn't scale.

Steps to reproduce

  • Add an image to the ckeditor
  • Resize it
  • Save the page and verify the resize
  • Edit the page and try to resize image again
  • The resize handles will expand width wise, but height doesn't. Also the image fails to scale with resize handles

Proposed resolution

Investigate the media resize filter to see if a similar fix to a previously fixed resize issue
https://www.drupal.org/project/ckeditor_media_resize/issues/3379751 πŸ› Unable to change resize after initial save Fixed
can be expanded on to address this.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States hablat

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

Merge Requests

Comments & Activities

  • Issue created by @hablat
  • πŸ‡ΊπŸ‡ΈUnited States hablat

    Added a possible fix as an MR. If others could please test. Thanks

  • πŸ‡ΊπŸ‡ΈUnited States damondt

    I appreciate the work on this, wysiwyg image resizing is fundamental to content editing.

    That said this patch did not work when I tested, looking at the patch the $node->setAttribute call changing the data-view-mode attribute is negated by a following change of that attribute. Changing the order also didn't get it working for me though.

  • πŸ‡ΊπŸ‡ΈUnited States hablat

    @damondt The only place I can see it being set somewhere else is here

        if ($apply_image_styles) {
          $view_mode = $this->getViewModeByWidth($width, $ckeditor5_plugin_config);
          if ($view_mode) {
            $node->setAttribute('data-view-mode', $view_mode);
          }
        }
    

    But that code only runs when your not in the editor because $apply_image_styles is only set to true outside of the editor

        // Apply image styles only if the corresponding setting in the text format
        // configuration is enabled and if the filter is NOT processing during the
        // loading of the text inside the ckeditor.
        $apply_image_styles = !empty($ckeditor5_plugin_config['apply_image_styles']) && !$processing_in_editor;
    

    Make sure you have the filtering order is set correctly for the text format your using. The Resize media images filter needs to run before the Embed media filter.

Production build 0.71.5 2024