Problem/Motivation
The Editor entity's settings contains per-text editor plugin settings.
CKEditor 5 allows two keys:
toolbar— order is meaningful hereplugins— order is not meaningful here
Because plugins' order is not meaningful, it can often be a pain to write tests for expectations around this. And it means config export orders can change around, leading to meaningless diffs.
Proposed resolution
Follow the precent set by \Drupal\user\Entity\Role::preSave() (in #2409129: Enforce order of permissions in config export), \Drupal\filter\Entity\FilterFormat::preSave(), etc. — and introduced by #2852557: Config export key order is not predictable, use config schema to order keys for maps.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #45 | 3314770-45-9.4.x.patch | 10.88 KB | wim leers |
| #45 | interdiff.txt | 3.73 KB | wim leers |
| #41 | 3314770-40.patch | 9.78 KB | wim leers |
| #41 | interdiff-35-40.txt | 721 bytes | wim leers |
| #39 | interdiff_35-39.txt | 1.58 KB | Ratan Priya |
Comments
Comment #2
wim leersThis will need a post-update hook for CKEditor 5. That means it'll need different test coverage for <10.0 and >=10.0, due to #3306545: Replace ckeditor with ckeditor5 in the 9.4.x database dumps in Drupal 10.0.x & 10.1.x.
Comment #3
wim leersThis will need a post-update hook for CKEditor 5. Last time we did that was in #3222756: Allow using images from external source.
Comment #4
wim leersComment #5
wim leersFix.
Comment #6
wim leersComment #9
wim leersHm … that failed … without an error? 🙈
😬 This makes no sense!
Comment #10
wim leersBut now that the config export order is consistent, we should also make our tests consistent. That will also help upgrade paths being written for the CKEditor 4 → 5 upgrade path — #3232052: Drupal 10 & CKEditor 5 readiness is the first to run into this!
Bumping to because of the ecosystem impact.
Comment #11
wim leersImplements #10.
This should trigger failures in CKEditor 5's test suite. Failures that will force us to make things consistent, hence paving the path for contributed modules writing upgrade path tests 👍
Comment #13
wim leersUpdate expectations in
SmartDefaultSettingsTest.Comment #14
wim leersMaybe this explains the inexplicable failure I mentioned in #9, and which has been happening consistently? 🙈
Comment #16
wim leersYep, that was it!
Time to run all tests.
Comment #18
smustgrave commentedTested locally and the tests do fail without the changes.
I want to say the failures in #16 are random. Believe something is going on with Javascript tests but I'm wrong this can be moved back.
Comment #20
wim leers#16 actually had one failure I expected: Drupal core has tests that require the default config to match the actual config export order.
Agreed the functional JS test failures are unrelated though!
(I should not have tested 9.5, I meant to test 10.0 — as explained in #2, the patch will need to be tweaked for <10 versions due to DB fixtures being different.)
Comment #22
smustgrave commentedSo reviewing the failures I think they are random javascript ones.
Comment #23
bnjmnmDoc nit!
Could this and the other ksort get a comment acknowledging that the sorting does not impact the overall functionality, but is done for better DX + test writing?
I could see this confusing contributors who see this without having worked on this issue, with them mistakenly thinking the sort order is relevant to the functionality.
Comment #24
alexpottWe can enforce the order of the plugins via config schema. I.e.
This will ensure that the order is always the expected order no matter where the write comes from.
Comment #25
wim leers#24: 🤯 This is not even in https://www.hojtsy.hu/blog/2021-dec-22/major-drupal-configuration-schema...!!!
Comment #26
wim leersIronically, for one of the two uses in total in all of Drupal core of
orderby, it turns out I suggested it: #2900700: Add orderby to content_moderation schema sequences. 🙈 But that's only because I had just seen the change record for it probably: https://www.drupal.org/node/2852566Implemented #24, and audited all
type: sequenceoccurrences in the CKEditor 5 module while I was at it.Comment #27
alexpottI don't get the comment here - this is not a core test to extend.
Comment #28
wim leersYou're right — it's not in the test. 🙈 I tried to do what @bnjmnm asked but did so poorly. I think just stressing the better DX will have to do then.
I did try to not add that logic and instead call some method on the config object to get the logic in
\Drupal\Core\Config\StorableConfigBase::castValue()to get executed. But that only gets executed when the config is stored. Storing the config is not necessary.And … that made me realize I could just sacrifice some test performance to allow code to be simpler! I'll just save the generated config unnecessarily, and then
orderbygets applied 🤓Comment #30
smustgrave commentedRan the tests locally and verified they do fail without the full patch.
The failure in #28 appears to be random javascript failure.
+1 for RTBC
Comment #31
wim leersComment #32
wim leers⚠️ This is now hard-blocking #3232052: Drupal 10 & CKEditor 5 readiness — other than that that module is ready to get CKEditor 5 support. Over 80,000 Drupal 9 contrib sites cannot update to CKEditor 5 until that gets committed and ships.
Comment #33
wim leersForgot to say in #32: this is no longer a soft blocker, but a hard blocker.
Especially now that
editor_advanced_linkis also usingorderbyfor itstype: sequenceconfig.Comment #34
bnjmnmThere's a change to a comment I'd like to see and I'd be good to RTBC after that.
Change to:
// Nothing to do if there are fewer than two plugins with settings.Comment #35
smustgrave commentedMade the change.
It was so minor so wouldn't be offended if it's not counted for credit haha
Comment #36
bnjmnmThis looks good then,
orderbyis a good way to do it, and went through the symfony docs to confirm that. While I didn't confirm if theorderby: ~additions are needed, but I do think they're helpful as it provides context for which items need ordering vs which don't. I'm going to RTBC under with the hope that the one line doc change doesn't cause test failures somehow.Comment #37
wim leersThey are indeed not needed, they're the implicit default. I like things to be explicit — and by setting them explicitly here, we leave no room for doubt that this is the intended behavior: the order in which items appear in the sequence matters! 👍
Comment #38
catchOne ultranit, I think we can just remove the two characters on commit?
What is the O?
I think this is OK, but maybe we should have a follow-up to apply it to the rest of core?
Comment #39
Ratan Priya commented@catch,
Made changes as per comment #38.
Needs Review.
Comment #40
bnjmnmPatch #39 includes removals that were not requiested. In #38 the
orderby: ~was accompanied by "I think this is OK" - i.e. it doesn't need to be removed.. @catch also said it was fine to remove those two stray characters on commit.#35 is still something I'm comfortable RTBCing, provided those two characters are removed on commit, but I'm also wary of a not-the-most-recent patch being what gets committed. I'm happy to RTBC if someone either reposts #35 or an updated patch that is #35 without the two extra chars.
Comment #41
wim leers#39: you removed all the
orderby: ~entries — those were intentional, per #37 :/#38: Hah, nice catch! 2 excess characters indeed. A core issue for that already exists: #2855675: Add orderby key to all sequences in core.
Comment #42
catchCommitted/pushed to 10.1.x, cherry-picked to 10.0.x and 9.5.x.
Needs a 9.4.x version if we want to commit it there.
Comment #44
wim leersComment #45
wim leersThe difference between 9.4 and all other branches is explained in #2. Of course this won't need to change default config.
So that means the interdiff represents just the additional changes to be able to test this in 9.4.
Comment #47
wim leersI was able to reproduce #45's failure on PHP 8.1, but not on PHP 8.0.
But the weird thing is that I cannot for the life of me figure out what is causing this. I even added
… and it just does not fire! 🤯 I can't figure this out.
Comment #48
bnjmnmThis seems to be consistently failing on 9.5.x too.
There are differences between the drupal-9.4.0.filled.standard.php.gz on Drupal 9.5.x and 10.1.x that have me wondering how tests passed on 9.5 at all.
10.x includes an editor.editor.basic_html that includes
On the 9.5, the same config has an empty plugins array
So the
in
testUpdatePluginSettingsSortPostUpdateshouldn't work since empty === empty.I feel like this may not be the whole story unless 9.5 has been failing for the past 4 days since this was committed? It does look like there are intentional differences between the fixtures #3306545: Replace ckeditor with ckeditor5 in the 9.4.x database dumps in Drupal 10.0.x & 10.1.x. For the test to work in 9x presumably we'd need to first convert the editor to CK5?
Comment #49
wim leersQuoting myself from #20:
So … @bnjmnm is absolutely right when he says — looks like @catch cherry-picked this to
9.5.xeven though there wasn't a green test run for it yet 😅(A mistake easily made when we are cherry-picking to
9.5.xmostly with ease, and when we are constantly updating FOUR branches…)We should revert the https://git.drupalcode.org/project/drupal/commit/0f4b07e commit.
Comment #51
catchOops. Reverted!
Comment #52
wim leersQueued 9.5 tests for #45.
@bnjmnm said he'd take a look at #47, because I'm … stumped 😬
Comment #53
smustgrave commentedShould this go back into Needs work?
Comment #54
smustgrave commentedFor the things in #52
Comment #55
wim leersSo … I see that we lost track of this 😬 But
9.5.0is on the verge of being released. So … I think this means that we just don’t commit it to9.5.xanymore? At this point, that just means that backporting some fixes to9.5.xwill be slightly more painful, sometimes, but it's not the end of the world I think.Comment #56
longwaveAgree with #55. This is too late now for 9.5.0, as a task it is ineligible for commit in a patch release, and so we will just have to live with it. A reminder that we should test patches on all branches before commit, especially majors where things might have diverged even if cherry pick is clean!