Problem/Motivation

CKEditor 4 enables image resizing when width and height attributes are allowed by the HTML filter.

Proposed resolution

Similar to this, we should allow enabling image resizing in the UI. Instead of using the HTML filter as the trigger, we could provide checkbox in the plugin configuration form.

Remaining tasks

Reviews.

User interface changes

  • Image resizing available by default when image plugin is enabled.
  • Image resizing can be disabled in CKE5 admin UI.
  • Add the "original size" resize option to the image toolbar. This is a feature addition, but it is something built into CKEditor 5 and easy to incorporate, it just needs to be enabled in config. Not having a way to revert to original size in CKEditor 4 was a pain point - this is a simple, desirable addition.

API changes

See https://www.drupal.org/node/3262942

Data model changes

None.

Issue fork drupal-3224652

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:

Issue fork ckeditor5-3224652

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lauriii created an issue. See original summary.

Wim Leers’s picture

Issue tags: +stable blocker
Wim Leers’s picture

Related issues: +#3222847: <img width height>
Wim Leers’s picture

Assigned: Unassigned » lauriii
Priority: Normal » Major
Related issues: +#2061377: [drupalImage] Optionally apply image style to images uploaded in CKEditor 5

Assigning to @lauriii because AFAIK he already did most of this in an earlier iteration of #3222847: <img width height>. It just got descoped from there.

See #3222847-6: <img width height>.

Furthermore, what @lauriii wrote in #3222847-5: <img width height>.1 would also pretty much solve #2061377: [drupalImage] Optionally apply image style to images uploaded in CKEditor 5. In fact, I think that would be superior to arbitrary px sizes… 🤓 🤔

Given the major UX impact this has and the considerations in the previous paragraph … I think this qualifies as at least "major".

Wim Leers’s picture

Title: Provide configuration option to enabling image resizing » Add ckeditor5-image's imageresize plugin
Parent issue: » #3211049: [META] Add all plugins which are available in Drupal core's build of CKEditor 4
Wim Leers’s picture

Title: Add ckeditor5-image's imageresize plugin » Add ckeditor5-image's imageresize plugin to allow image resizing
Wim Leers’s picture

vlyalko made their first commit to this issue’s fork.

Wim Leers’s picture

Project: CKEditor 5 » Drupal core
Version: 1.0.x-dev » 9.3.x-dev
Component: Code » ckeditor5.module
Assigned: lauriii » Unassigned

Wim Leers’s picture

Title: Add ckeditor5-image's imageresize plugin to allow image resizing » [drupalImage] Add ckeditor5-image's imageresize plugin to allow image resizing
Status: Active » Needs work

The only commit made by @vlyalko is basically doing this:

diff --git a/ckeditor5.ckeditor5.yml b/ckeditor5.ckeditor5.yml
index f1e0f24..f6413d6 100644
--- a/ckeditor5.ckeditor5.yml
+++ b/ckeditor5.ckeditor5.yml
@@ -381,6 +381,8 @@ ckeditor5_image:
     plugins:
       - image.Image
       - image.ImageToolbar
+      - image.ImageResize
+      - image.AutoImage
       - drupalImage.DrupalImage
     config:
       image:

… which means it was very easy to port her work into a core merge request! 😊

Next step: port everything imageresize-related that was deleted in https://git.drupalcode.org/project/ckeditor5/-/merge_requests/72/diffs?c....

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Wim Leers’s picture

I don't think we need to add AutoImage here — that feels out of scope.

Wim Leers’s picture

Version: 9.4.x-dev » 9.3.x-dev
Issue tags: +Needs tests, +Needs change record

@lauriii, @bnjmnm and I discussed this issue. We all greed image resizing functionality should be enabled by default, but possible to disable. This matches the state of CKEditor 4, but many sites don't actually want to allow their end users to resize images arbitrarily, and use image styles instead for example (also see #2061377: [drupalImage] Optionally apply image style to images uploaded in CKEditor 5).

Just paired with @hooroomoo and in the process of explaining how to make resizing configurable, but then realized this is a chicken-and-egg problem. :/

This is functionality that has no toolbar item, and is just available as soon as images are supported. So none of the existing condition types work. Therefore we need some new infrastructure …

ifConfigurationMatches

I just pushed a commit that introduces a new condition type: ifConfigurationMatches. This allows you to specify a condition that requires the specified configuration subset to match (exactly). Tagging Needs change record for this.

Thanks to \Drupal\ckeditor5\Plugin\Editor\CKEditor5::shouldHaveVisiblePluginSettingsForm(), this is already guaranteed to be visible in the admin UI at the right time, so that's at least one already solved chicken-and-egg problem.

With this new infrastructure, we can define:

    conditions:
      ifConfigurationMatches:
        allow_resize: true
      plugins: [ckeditor5_image]

(i.e. the ckeditor5_imageResize plugin should be enabled when the ckeditor5_image plugin is active and the configuration for the ckeditor5_imageResize contains exactly

allow_resize: true

This happens to be the default (see top of the comment). If the user unchecks the checkbox in the CKEditor 5 admin UI, the resizing functionality is disabled.

Next steps

  1. Test coverage
  2. configure resizeOptions: https://ckeditor.com/docs/ckeditor5/latest/api/module_image_image-ImageC...

hooroomoo made their first commit to this issue’s fork.

hooroomoo’s picture

@Wim Leers I'm having trouble understanding the structure of the \Drupal\Tests\ckeditor5\Kernel\CKEditor5PluginManagerTest::providerTestInvalidPluginDefinitions() and might need an overview of it.

Wim Leers’s picture

#18: Happy to walk you through it later today! 😊

Basically, :: providerTestInvalidPluginDefinitions () has every possible structural permutation of a CKEditor 5 plugin definition, to ensure that each mistake an implementer could make actually provides helpful error messages.

This is an atypical kind of test coverage in Drupal, but we're trying to make CKEditor 5 have a better DX than any other core module. With new territories come new patterns 🤓

And I can see that you're already well on your way with that actually! 😄👍

hooroomoo’s picture

Status: Needs work » Needs review
FileSize
47.37 KB

I'm still unable to disable the resize plugin. (I have hit the Save button) and I also get this error in the screenshot whenever I uncheck the box.

I also added resize options and I see them in the editor data but not in the UI. Does there need to be extra configuration for that?

Wim Leers’s picture

Reproduced. I don't know why I wasn't able to reproduce this earlier … sorry about that!

Wim Leers’s picture

Now it should work fine again :)

This refines the code that #3248177: Language toolbar item cannot be removed from the toolbar introduced. I probably originally tested this with a state where that issue had not yet been merged.

Wim Leers’s picture

Status: Needs review » Needs work

Addressing my own feedback — this is delving into the tricker aspects of the plugin system and the configuration system 🤓

Wim Leers’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests, -Needs change record

@hooroomoo added tests.

I just addressed the feedback I wrote on the MR. This now definitely needs review from someone other than @hooroomoo and I.

Wrote change record: https://www.drupal.org/node/3262942.

In writing that, I suspect that requiresConfiguration would be a better name than ifConfigurationMatches?

Wim Leers’s picture

Issue summary: View changes
bnjmnm’s picture

Status: Needs review » Needs work

Spotted a few tiny things in the MR.

In writing that, I suspect that requiresConfiguration would be a better name than ifConfigurationMatches?

I support changing it. configuration is potentially more consistent with the other condition names, but I also see the benefits in expanding that to requiresConfiguration since 'configuration' is a term used in many different contexts throughout this module.

hooroomoo’s picture

Status: Needs work » Needs review

I like requiresConfiguration better too. Addressed above feedback including the name change to requiresConfiguration and updated change record.

Resize option has one option of changing it back to its original size now.

Wim Leers’s picture

Wonderful, thank you so much for that thoroughness, @hooroomoo! 😊

bnjmnm’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

All my feedback is addressed. Image resizing works great, as does the "original size" option. The bulk of the issue is the requiresConfiguration constraint and the surrounding testing, which all looks good. A big helping of constraints and tests is a little more to review, but provides me assurance that CKEditor 5 will be easier to maintain long term as it catches a wide variety of potential problems and provides useful, targeted feedback.

lauriii’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests
FileSize
98.79 KB

This isn't working as expected because the image resize form is displayed even when the image upload has been disabled:

Wim Leers’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Wim Leers credited huzooka.

Wim Leers’s picture

Also, I want to credit @huzooka for his instrumental help on this issue, to get FunctionalJavascript tests running on my local machine again, which is how I was able to write the test!

Thanks again! 😊

Wim Leers’s picture

In #16 I wrote:

Thanks to \Drupal\ckeditor5\Plugin\Editor\CKEditor5::shouldHaveVisiblePluginSettingsForm(), this is already guaranteed to be visible in the admin UI at the right time, so that's at least one already solved chicken-and-egg problem.

I was wrong 🤓

https://git.drupalcode.org/project/drupal/-/merge_requests/1421/diffs?co... solves that.

Wim Leers’s picture

Wim Leers’s picture

All feedback addressed.

bnjmnm’s picture

Status: Needs review » Reviewed & tested by the community

The changes since #30 (which I'm 🤦‍♂️ to have missed) address the issue identified with excellent test coverage to back it up. I did another round of full code review while I was there and spotted a few additional nits in the added tests or things I didn't catch during initial review. This seems to be in good shape now, so RTBC 😎.

Wim Leers’s picture

In reviewing another CKE5 issue, I realized this was not yet updating ckeditor5.api.php. Fixed that. Used the same language as in the change record.

Wim Leers’s picture

And … converted to patches, so we can test this against all 3 branches. Due to the JS changes in 10.0.x we need a separate patch for that. Differences shown in attached TXT file.

lauriii’s picture

Issue tags: +Needs reroll
Wim Leers’s picture

  • lauriii committed e8aaf37 on 10.0.x
    Issue #3224652 by Wim Leers, hooroomoo, vlyalko, lauriii, bnjmnm,...

  • lauriii committed fa8929e on 9.4.x
    Issue #3224652 by Wim Leers, hooroomoo, vlyalko, lauriii, bnjmnm,...
lauriii’s picture

Committed e8aaf37 and pushed to 10.0.x. Committed 9.x patch to 9.4.x. Thanks!

Leaving open for 9.3.x backport once the freeze is over.

  • lauriii committed f6dbd06 on 9.3.x
    Issue #3224652 by Wim Leers, hooroomoo, vlyalko, lauriii, bnjmnm,...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Cherry-picked to 9.3.x. Thank you!

Wim Leers’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

joelpittet’s picture

I see the resizeUnit wasn't discussed when this went in, I'm hoping to change it to px over here #3348603: CKEditor 5 resizes images with % width instead of px width (the CKEditor 4 default): breaks image captions *and* is a regression.

k-cogs’s picture

Has anyone had luck getting image resizing to work with embedded media library items or is this issue tracked anywhere?

fsayoub’s picture

k-cogs

Successfully applied this patch, along with Austin's instructions and all is well 👍

https://www.drupal.org/project/drupal/issues/3359725#comment-15089658