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.
Comment | File | Size | Author |
---|---|---|---|
#41 | conflict.txt | 904 bytes | Wim Leers |
#41 | 3224652-41-10.0.x.patch | 32.09 KB | Wim Leers |
| |||
#41 | 3224652-41-9.3.x-9.4.x.patch | 32.12 KB | Wim Leers |
#39 | 3224652-39-mr-commit-250fba0f7c93e482759c06ae0647b1a0f8bc7004-10.0.x.patch | 32.07 KB | Wim Leers |
| |||
#39 | 3224652-39-mr-commit-250fba0f7c93e482759c06ae0647b1a0f8bc7004-9.3.x-9.4.x.patch | 32.1 KB | Wim Leers |
Issue fork drupal-3224652
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:
- 3224652-imageresize changes, plain diff MR !1421
1 hidden branch
Issue fork ckeditor5-3224652
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:
Comments
Comment #2
Wim LeersComment #3
Wim LeersComment #4
Wim LeersAssigning 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".
Comment #5
Wim LeersComment #6
Wim LeersComment #7
Wim Leers@vlyalko started working on this over at #3247974! I asked her in #3247974-4: [drupalImage] Image resize, Image with text wrapped shown correctly on front end and not correctly shown in backend to post her code here 😊
Comment #10
Wim LeersComment #13
Wim LeersThe only commit made by @vlyalko is basically doing this:
… 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....Comment #15
Wim LeersI don't think we need to add
AutoImage
here — that feels out of scope.Comment #16
Wim Leers@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 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:
(i.e. the
ckeditor5_imageResize
plugin should be enabled when theckeditor5_image
plugin is active and the configuration for theckeditor5_imageResize
contains exactlyThis 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
resizeOptions
: https://ckeditor.com/docs/ckeditor5/latest/api/module_image_image-ImageC...Comment #18
hooroomoo@Wim Leers I'm having trouble understanding the structure of the \Drupal\Tests\ckeditor5\Kernel\CKEditor5PluginManagerTest::providerTestInvalidPluginDefinitions() and might need an overview of it.
Comment #19
Wim Leers#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! 😄👍
Comment #20
hooroomooI'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?
Comment #21
Wim LeersReproduced. I don't know why I wasn't able to reproduce this earlier … sorry about that!
Comment #22
Wim LeersNow 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.
Comment #23
Wim LeersAddressing my own feedback — this is delving into the tricker aspects of the plugin system and the configuration system 🤓
Comment #24
Wim Leers@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 thanifConfigurationMatches
?Comment #25
Wim LeersComment #26
bnjmnmSpotted a few tiny things in the MR.
I support changing it.
configuration
is potentially more consistent with the other condition names, but I also see the benefits in expanding that torequiresConfiguration
since 'configuration' is a term used in many different contexts throughout this module.Comment #27
hooroomooI 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.
Comment #28
Wim LeersWonderful, thank you so much for that thoroughness, @hooroomoo! 😊
Comment #29
bnjmnmAll 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.Comment #30
lauriiiThis isn't working as expected because the image resize form is displayed even when the image upload has been disabled:
Comment #31
Wim LeersTests written: https://git.drupalcode.org/project/drupal/-/merge_requests/1421/diffs?co... → this should fail.
Comment #33
Wim LeersAlso, 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! 😊
Comment #34
Wim LeersIn #16 I wrote:
I was wrong 🤓
https://git.drupalcode.org/project/drupal/-/merge_requests/1421/diffs?co... solves that.
Comment #35
Wim LeersWhile working on 225ee3db, discovered a bug in existing tests: #3264451: ImageTest::testWidth() has wrong selector, but no assertion: increases DrupalCI by 20 seconds.
Comment #36
Wim LeersAll feedback addressed.
Comment #37
bnjmnmThe 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 😎.
Comment #38
Wim LeersIn 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.Comment #39
Wim LeersAnd … 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.Comment #40
lauriiiComment #41
Wim LeersRerolled after #3264451: ImageTest::testWidth() has wrong selector, but no assertion: increases DrupalCI by 20 seconds introduced a conflicting change. Note that we cannot yet test this against
9.3.x
because #3264451 has not yet been committed to 9.3.Comment #44
lauriiiCommitted 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.
Comment #47
lauriiiCherry-picked to 9.3.x. Thank you!
Comment #48
Wim LeersPublished CR: https://www.drupal.org/node/3262942
Comment #50
joelpittetI see the
resizeUnit
wasn't discussed when this went in, I'm hoping to change it topx
over here #3348603: CKEditor 5 resizes images with % width instead of px width (the CKEditor 4 default): breaks image captions *and* is a regression.Comment #51
k-cogs CreditAttribution: k-cogs commentedHas anyone had luck getting image resizing to work with embedded media library items or is this issue tracked anywhere?
Comment #52
fsayoub CreditAttribution: fsayoub as a volunteer commentedk-cogs
Successfully applied this patch, along with Austin's instructions and all is well 👍
https://www.drupal.org/project/drupal/issues/3359725#comment-15089658