Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Discovered in #3270438: Remove CKEditor 4 from core. See #3270438-9: Remove CKEditor 4 from core.4 + #3270438-11: Remove CKEditor 4 from core.
Steps to reproduce
N/A
Proposed resolution
Stop using CKEditor 4 module's Editor
plugin in tests; use \Drupal\editor_test\Plugin\Editor\UnicornEditor
or \Drupal\editor_test\Plugin\Editor\TRexEditor
instead.
Remaining tasks
CKEditor 5
Update→ info in #35SmartDefaultSettingsTest
Update→ done in #5CKEditor5AllowedTagsTest
Update\Drupal\Tests\ckeditor5\FunctionalJavascript\AdminUiTest
Text Editor
UpdateEditorDialogAccessTest</del>
UpdateEditorPrivateFileReferenceFilterTest</del>
UpdateEditorAdminTest
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
Comment | File | Size | Author |
---|---|---|---|
#58 | 3270734-58-9.4.x.patch | 29.6 KB | Wim Leers |
#57 | 3270734-57-9.4.x.patch | 28.21 KB | Wim Leers |
#28 | 3270734-28.patch | 14.21 KB | Wim Leers |
| |||
#28 | interdiff.txt | 3.04 KB | Wim Leers |
#25 | interdiff.3270734.18-25.txt | 2.69 KB | longwave |
Issue fork drupal-3270734
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:
- 3270734-update-editor- changes, plain diff MR !2665
Comments
Comment #2
Wim LeersComment #3
xjmComment #4
xjmComment #5
Wim LeersHere's a kickstart for this issue, thanks to a planning meeting during which I was partially idle 🤓
This updates all of
CKEditor5AllowedTagsTest
's test methods (3 of the 8 affected) to not rely on CKEditor 4.Comment #6
Wim LeersThat's funny: this test now fails.
Because the CKEditor 5 module only took the liberty of fixing #3245351: Should switching text editors retain image upload settings? for the CKE 4 → 5 upgrade path, not for switching from some other text editor.
So if we want this to pass, we also need to broaden that fix, but it's still isolated to CKEditor 5, that upstream bug should still be fixed, and fixing it is out of scope here.
Comment #7
Wim LeersComment #8
Wim LeersComment #10
Wim LeersStill applies. Re-testing.
Comment #11
longwaveThe patch looks OK to me - mostly just swapping ckeditor for the test unicorn editor - but it no longer applies.
Comment #12
andregp CreditAttribution: andregp at CI&T commentedHere is a simple reroll :)
Comment #14
xjmThe fail in #12 looks relevant.
Comment #15
ameymudras CreditAttribution: ameymudras at Salsa Digital commentedRe rolled the above patch
Comment #16
ameymudras CreditAttribution: ameymudras at Salsa Digital commentedAdding another patch after phpcs fixes
Comment #18
Wim LeersPatch no longer applies.
Starting from #6 again, which was the last green test run.
Did not run test suite locally because once again dealing with
chromedriver
hell. Hopefully it passes 🤞Comment #19
Wim LeersThere are still plenty of remaining tasks listed in the issue summary though.
Comment #20
longwaveRan this locally to find the failure as the DrupalCI output is unhelpful. The real error is:
ie.
<img src alt data-entity-type data-entity-uuid>
is missing.Comment #21
longwaveIf I fix that by making $defaultElementsAfterUpdatingToCkeditor5 match, then it crashes further into the test:
This is because of an error on the page:
Not sure how to fix this,
Comment #22
Wim Leers#21: Hm, I'd swear I've seen that same crash months ago and that it was fixed. Maybe I misremember. A quick search revealed that indeed exactly this was fixed and even has explicit test coverage (see #3274648: HTMLRestrictions::merge() and ::toGeneralHtmlSupportConfig() fail on allowed attribute values that can be interpreted as integers). I wonder what I'm missing. Can you put a breakpoint on that line and check what exact input is causing this crash? 🙏
Semi-good news: getting the current patch back to green is only part of what needs to happen here! See the issue summary for the other tests that need to be updated to not use CKEditor 4 anymore 🤓 So while we figure out what's going on in #21, we can already proceed with the other parts. 👍
Comment #23
Wim LeersThis is now hard-blocking #3304326: Deprecate CKEditor 4 module in 9.5.
Comment #24
longwaveThis was a tricky one to debug! The issue is
HTMLRestrictions::mergeAllowedElementsLevel()
when passed a numeric key, which misbehaves thanks to PHP's loose typing.A minimal test case is
<ol type='1'>
. Eventually this gets recursed down into:When called with these arguments,
::mergeAllowedElementsLevel($array1, $array2)
incorrectly returns[1, TRUE]
. This is becausearray_keys($array1)
casts the string key1
to int!And when we have a numeric key,
array_merge()
acts differently at the end of the method, and a corrupted array is produced.PHP seems determined to treat the string key
1
as an integer, so the only fix that I can see is to avoid usingarray_merge()
. If I replace this with a loop that sets the keys then the test passes for me.This does seem identical to #3274648: HTMLRestrictions::merge() and ::toGeneralHtmlSupportConfig() fail on allowed attribute values that can be interpreted as integers and I'm not sure why the fix there appeared to work, but then hasn't worked here.
Comment #25
longwaveNow I've re-read what I've done, I see we just have a missing test case that will catch it.
Comment #27
Wim LeersWow, you found a "sub edge case" that we missed in #3274648! 👏 😅 Nice detective work & great comment in #24!
#25 looks great! But now we need the other remaining tasks to still be addressed — any chance you could take that on? 🤞
Here's a review in the meantime:
The point of this was to retain image upload settings, regardless of which text editor is the original one: CKEditor 4 or any other.
(#3245351: Should switching text editors retain image upload settings? will fix this in the Text Editor module.)
It makes sense that we cannot do this: the Text Editor plugin itself is responsible for exposing image upload settings in some way. But because we switch from the CKEditor 4 text editor to the Unicorn text editor, there is no form element anymore to enable/disable image uploads.
… which brings me to my point: we should NOT need this! The first hunk I commented on should make this happen automatically when switching to CKEditor 5.
But I think the fact that there is no form element is what is causing all this weirdness!
P.S.: I wrote this 🙈
… I think all of this could be solved (read: omitted from the patch) by adding this:
Comment #28
Wim LeersFunctional JS tests are once again not working because of Chrome +
chromedriver
shenanigans. No time to mess with that tonight. Here's hoping I getEditorAdminTest
changes right the first time 🤓Comment #29
longwaveI've tried this locally but I don't think the logic in #27 is correct.
#27.1 retains image upload settings, but nothing then adds the image upload button to the toolbar. In the case of the Unicorn editor there are no HTML restrictions so
addToolbarItemsToMatchHtmlElementsInFormat()
returns early and adds nothing. Only bold and italic are present in the toolbar by default.#27.2 *can* be removed (ie. the assertion can be re-added) if the Unicorn editor supports image uploads via implementing
editor_image_upload_settings_form()
.#27.3 Because of #27.1, the toolbar button must still be manually added.
Comment #30
longwaveSmartDefaultSettingsTest relies heavily on existing CKEditor 4 config. Not sure how we can replace this with Unicorn editor and keep the test coverage intact for upgrading from CKEditor 4? As an example of the sort of thing that will be hard to replace with Unicorn editor:
Unicorn editor has no concept of toolbar buttons or integration with media library that I can see. But adding it to Unicorn editor is building a huge test stub for no benefit other than decoupling the test - the test itself doesn't feel like it would be testing the real world upgrade path any more.
It feels like we will need some kind of CKEditor 4 stub left behind (either as a skeleton ckeditor.module or rolled into CKEditor 5 module) as existing editor configs have dependencies on the module and schema, and we also need enough code left that we can test the upgrade path.
Comment #32
longwaveThe addition of image uploads to Unicorn editor in #27 *has* made the conversion of the editor image upload tests from CKEditor to Unicorn editor much easier, however! All tests are addressed except SmartDefaultSettingsTest, which as stated above I'm really not sure how to handle without losing valuable upgrade test coverage.
Oh, and I converted to an MR because patches were getting too difficult to handle, and I can make atomic commits which should be easier to review.
Comment #33
Wim LeersBeen trying all day to get to this, but it's now past 19:00 and my day has been sunk into #3222756: Allow using images from external source — assigning this to myself for tomorrow 🤓
Comment #35
bnjmnmI'd already converted the CKEditor 4 config to be fixtures in #3271097: Replace CKEditor 4 with CKEditor 5 in the Standard profile and StandardTest so we could continue testing the upgrade path. That issue hasn't landed yet, so I added those changes to the MR here as well. If a merge conflict arises I don't think it will be a difficult one.
Comment #36
bnjmnmComment #37
longwaveThanks @bnjmnm. Rebased against 10.0.x.
If I now remove
ckeditor
fromSmartDefaultSettingsTest::$modules
the config can be installed we run into the same problem I describe in #3304736-10: Provide a good UX to ensure the CKEditor 4 to 5 update is always done before upgrading to Drupal 10 unless the contrib module is installed - the fixtures depend on theckeditor
plugin, which has to remain in some form in Drupal 10 for the upgrade path and related tests to still function. Therefore I think for the purposes of this issue SmartDefaultSettingsTest has to keep its dependency onckeditor
module and we have to solve all this in a followup.Comment #38
bnjmnmI added a
fackeditor
module to CKEditor 5's test modules. It is a find/replace copy of the CKEditor module with everything stripped out thatSmartDefaultSettingsTest
doesn't need (that I'm aware of). This works for me locally, now lets see if the testbot is OK with it.Comment #39
Wim Leers#37: That problem is solved in #3304736-14: Provide a good UX to ensure the CKEditor 4 to 5 update is always done before upgrading to Drupal 10 unless the contrib module is installed now! 👍🤓
#38: 🤣👏
Let me try using the approach that #3304736-14: Provide a good UX to ensure the CKEditor 4 to 5 update is always done before upgrading to Drupal 10 unless the contrib module is installed introduced to avoid adding (well, copying) many dozens of files from
core/modules/ckeditor
intocore/modules/ckeditor5/tests/modules/fackeditor
🤞 To quickly prove that, I'm going to modify the MR to only run CKE5 tests, cherry-pick that commit from the other issue, and observe what happens. 🤓Comment #40
Wim LeersYay, that got us past it! So this should be a viable path forward with far less code! 🤞
But now the failures are in a different spot:
Line 121 of
Editor.php
is in here:… we're literally just crashing now on RE-calculating dependencies for Text Editor config entities that should not be recalculated because we're talking about a test fixture here!
And that's only because the test is doing things like:
… even though that really should be created that way. Let me figure out the optimal way to install configuration! 🤓
Comment #41
Wim LeersYay, got past that too, next:
https://git.drupalcode.org/project/drupal/-/merge_requests/2665/diffs?co... made that green 👍
Comment #42
Wim LeersReviewed. This is almost RTBC. 3 questions remain 😊
Comment #43
longwaveThe MR comments all seem related to the fact that Unicorn is a very simple editor and the test format doesn't provide any HTML restrictions or any other filters for that matter. While Unicorn has image uploads configured, SmartDefaultSettings doesn't explicitly know that it supports images, and so it doesn't add the image upload toolbar button.
It could equally be argued that when upgrading Unicorn, we should be adding *all* the toolbar buttons by default, as it technically supports anything due to the lack of filters. Are there any real world examples of editors other than CKEditor 4 in use, that are planning a migration path to CKEditor 5? If not, I'm not sure I see much value in these Unicorn test cases, when it's not really a full implementation - we should just test a real CKEditor config instead.
We already special case CKEditor 4 in SmartDefaultSettings:
But maybe SmartDefaultSettings should *only* work with CKEditor 4? If we need a special case here, what's to say we don't need special cases for other editors?
Comment #44
lauriiiTriggering test bot
Comment #45
Wim LeersSo my 3 remaining concerns were all about test coverage: I want to make sure we do not lose test coverage.
Looks like I trolled myself, because all 3 were introduced by myself in #5 🙈
testImageUploadsRemainEnabled()
: the// Enable the image upload toolbar item.
additiontestSwitchToVersion5()
: the$this->assertSession()->pageTextContains('The following attribute(s) are already supported by enabled plugins and should not be added to the Source Editing "Manually editable HTML tags" field: Image (<img src alt data-entity-uuid data-entity-type>)');
removal\Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5AllowedTagsTest::$defaultElementsWhenUpdatingNotCkeditor5
. Previously, it contained markup typical for CKEditor 4, i.e. including<img src alt data-entity-type data-entity-uuid>
. #5 removed that. Why? Because to test the behavior of switching to CKEditor 5, I created a fresh text format + editor … that used CKEditor 4. TheDrupalImage
button is placed in the CKEditor 4 toolbar by default (see\Drupal\ckeditor\Plugin\Editor\CKEditor::getDefaultSettings()
. This explains the presence of the<img>
tag.Switching to the Unicorn editor does not trigger that anymore.
Now, that's fine, except that this causes the
The following attribute(s) are already supported by enabled plugins and should not be added to the Source Editing "Manually editable HTML tags" field: Image (<img src alt data-entity-uuid data-entity-type>)
message to no longer appear, and that's something that is explicitly asserted in HEAD.Apparently April-Wim thought that it was fine to lose this test coverage. August-Wim is not so sure!
So I dug into this and … found that
\Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5AllowedTagsTest::testAllowedTags()
explicitly tests this in the UI! 👍 (And it's tested at the unit level in many scenarios in\Drupal\Tests\ckeditor5\Kernel\ValidatorsTest::testPair()
.) That means it's fine to simplifytestSwitchToVersion5()
and remove that assertion, because as the name of the test method indicates: that's not the intent of that particular test; it was actually just a distraction in that test 👍testSwitchToVersion5()
: the// Return to the confirm form and enable the image upload toolbar item.
additionDrupalImage
button being in the CKEditor 4 toolbar by default: the original test was also distracted with the fact that CKEditor 4 could be saved with image uploads being disabled, but CKEditor 5 does not allow that (at least not in HEAD, it will soon: #3222756: Allow using images from external source). So the proper fix is to just delete all that completely, resulting in a much easier to understand test! 🥳Comment #46
Wim LeersThat was green!
No more remarks. Let's do this! 🚢
(Yes, I wrote the very beginning of this patch. But then @longwave took it to the finish line. And as #45 shows, I've very strongly disagreed with my own initial patch in #5 🙈😅 All I did here was simplify clean up test fixtures — see #39 — and thoroughly verify that we do not lose any test coverage — see #45.)
Comment #47
longwave+1 RTBC to the bits I didn't write, this has been comprehensively worked on in the last week and I don't have anything more to add.
Comment #48
Wim Leers@lauriii pointed out in chat that
\Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5CKEditor4Compatibility
should be moved intocore/modules/ckeditor
too, otherwise we'd still have a test relying on CKE4 after removingcore/modules/ckeditor
in #3270438: Remove CKEditor 4 from core.Trivial change (pushed it already), so keeping at RTBC.
Comment #53
lauriiiCommitted f09840a and pushed to 10.1.x. Also cherry-picked to 10.0.x and 9.5.x. Thanks!
Comment #54
Wim LeersYay, this unblocked #3304326: Deprecate CKEditor 4 module in 9.5! 🎉
Comment #56
Wim LeersWe should still get this committed to
9.4.x
.The difference here is that we should not update the
editor
module's tests in9.4.x
. Only theckeditor5
module. And because #3271097: Replace CKEditor 4 with CKEditor 5 in the Standard profile and StandardTest obviously won't be backported to9.4.x
either, we need to change the tests slightly.Comment #57
Wim LeersComment #58
Wim LeersI need at least the
core/modules/editor/tests/modules/src/Plugin/Editor/UnicornEditor.php
hunk from the9.5.x
commit if this wants to be able to pass tests.Comment #59
Wim LeersGreen! 👍
Comment #61
catchCommitted 142f1c6 and pushed to 9.4.x. Thanks!
Comment #62
Wim LeersThanks!
Restoring previous issue state.