Problem/Motivation
While working on CKEditor 5, I noticed that I kept getting a CKEditor 5 validation error even after I was no longer on CKEditor 5. I first blamed the CKEditor 5 module.
Then I learned it's a bug in editor.module.
editor_form_filter_admin_format_validate
Steps to reproduce
- Install
ckeditor.module + ckeditor5.module
- Go to
/admin/config/content/formats/add
- Switch to CKEditor 5
- Switch to None
- Switch to CKEditor (4)
- Expected: CKEditor 4 admin UI
Actual: CKEditor 5 validation error (Invalid toolbar value.
) and no CKEditor 4 admin UI
Proposed resolution
Upon switching text editors (including to '' aka "None"), editor_form_filter_admin_format_validate() gets called before editor_form_filter_format_form_alter() … which means that $form_state still contains the old editor plugin.
Remaining tasks
Passing fix-only patch
Failing test-only patch; test can simply match the steps to reproduce above
Passing fix+test patch
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
Comments
Comment #2
wim leersComment #3
larowlanTriage fairy 🧚♂️
Comment #5
kristen polThanks for the issue and patch.
Moving back to "needs work" for tests.
Comment #6
mohit_aghera commentedAdding test cases and test-only patch.
Comment #8
marcvangendThanks for the fix and the test.
Re #6, maybe I'm missing something, but I don't quite understand why the test was implemented as a FunctionalJavascript test. The issue is about a form submit handler, so I assume it does not depend on the browser. If so, a Functional test (in the \Drupal\Tests\editor\Functional\EditorAdminTest class?) should suffice.
Comment #9
mohit_aghera commentedThanks for the feedback @marcvangend
The current form seems to be using Ajax and we need to wait till a response comes back.
For that, I needed some method that allows us to wait for ajax call.
Mainly functional Javascript test provides a similar method, so I considered that.
Comment #10
marcvangendSorry Mohit, you are absolutely right. This one is triggered by the select box, not by the save button. FunctionalJavascript is the way to go.
The code looks good to me, just one thought about the documentation. The order in which the different editors are tested (ckeditor > none > ckeditor5) is important to reproduce the error. I would like to see that documented in the test. Otherwise future developers may think it makes sense to re-order some lines and unknowingly break the test. How about something like this?
Comment #11
kristen polGood point @marcvangend. That would be a nice improvement.
Comment #12
kristen polMoving back to needs work for above feedback.
Comment #13
marcvangendNew patches to address #10.
Comment #15
kristen polThanks for the updated patch. Marking RTBC based on:
1. Issue summary is clear and up-to-date with steps to reproduce.
2. The only changes to latest patch are to the comments in the test.
3. Code was already tested in #5.
4. Test-only patch fails as expected.
5. Patch passes tests.
6. Code has already been reviewed above.
Thanks, everyone!
Comment #16
kristen polUpdated remaining tasks in issue summary.
Comment #18
mohit_aghera commentedTriggered the test bot again. Current pipeline failures seem different from to the changes we've made.
Update:
FunctionalJavascript tests seems flacky
Discussion thread: https://drupal.slack.com/archives/C1BMUQ9U6/p1644322854924229
Comment #19
wim leersThanks so much, @mohit_aghera and @marcvangend for adding test coverage! :D 🙏
Re-tested. The failures are definitely unrelated; they indicate infrastructure is broken.
Re-RTBC'ing because it was green a while ago, and nothing has changed in these code paths since then.
Comment #21
yogeshmpawarMarking RTBC again as test failures are unrelated.
Comment #23
catchCommitted/pushed to 10.0.x, cherry-picked to 9.4.x and 9.3.x, thanks!
Comment #25
wim leersYay! I just verified that there's nothing to update in
core/modules/ckeditor5, and this does fix the scenario described in the issue summary 👍