Problem/Motivation
When user switches a pre-existing text format to using CKEditor 5, they have to start from a blank slate. This is not the best possible user experience given that we could read the text format configuration, and create a starting point from that.
Proposed resolution
Read text format configuration when CKEditor 5 is enabled. If user has CKEditor 4 enabled, convert the toolbar configuration to CKEditor 5. If user doesn't have CKEditor 4 enabled, but has HTML filter enabled, generate CKEditor 5 configuration based on the allowed elements.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#34 | Screenshot 2021-08-04 at 13.10.25.png | 295.68 KB | Wim Leers |
#34 | Screenshot 2021-08-04 at 13.08.37.png | 881.65 KB | Wim Leers |
#30 | Screenshot 2021-08-02 at 16.24.49.png | 509.92 KB | Wim Leers |
#30 | Screenshot 2021-08-02 at 16.22.59.png | 317.49 KB | Wim Leers |
#17 | Screen Shot 2021-07-19 at 3.04.34 PM.png | 298.14 KB | bnjmnm |
Issue fork ckeditor5-3216015
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 Leers💯 Thanks for opening this issue! It'll be another essential next step on top of #3201637-2: Figure out how to prevent data loss during upgrade/migration path.
Comment #3
Wim LeersPostponed on #3201637-21: Figure out how to prevent data loss during upgrade/migration path.
Comment #4
Wim LeersThis is postponed on #3201637: Figure out how to prevent data loss during upgrade/migration path because only then will be able to write thorough tests.
But between #3201641: Improve the HTML filter configuration UX having landed and that issue being very close to shipping, I figured it's time to get us started here 😊
See the before vs after experience 🤩
Comment #5
Wim LeersThis part is 100% done for Drupal core CKEditor 4 plugins.
drush
command that #3201637: Figure out how to prevent data loss during upgrade/migration path is adding.This part is still TODO.
This made it very easy to see which buttons we do not yet have in CKEditor 5. Some of these probably should have an equivalent in CKEditor 5?
Comment #7
Wim Leers#3201637: Figure out how to prevent data loss during upgrade/migration path landed.
Comment #8
Wim LeersComment #9
Wim LeersPer #3215466-9: Attribute values not accounted for in CKEditor5PluginManager::getProvidedElements, this issue is blocked on that.
Comment #10
Wim Leers#3215466: Attribute values not accounted for in CKEditor5PluginManager::getProvidedElements landed :)
Comment #13
bnjmnmAssigning to myself. I made some nice progress, but this isn't in a state I'd want anyone to have to resume work on.
Comment #14
Wim Leers@bnjmnm great work here!
Pull in the latest commits against
1.0.x
, which solve:Thanks to pulling those in, switching
from CKEditor 4 to 5 no longer shows:but instead shows:
So … progress! 🥳🥳🥳
Comment #15
Wim LeersBased on #14 posted #3211049-5: [META] Add all plugins which are available in Drupal core's build of CKEditor 4 + #3222801-3: [META] Ensure CKE5 equivalent plugins of CKE4 generate/support equivalent markup 🥳🤓
Comment #16
Wim LeersOkay so ab80a78df resulted in the same number of test failures, but only 3 instead of 5 test case failures in
ValidatorsTest
. TheINVALID: the modified restricted_html text format (with filter_autop and filter_url removed)
andINVALID: HTML format: empty toolbar + default allowed HTML tags
test cases are now passing again. I'm not sure I properly understood why you originally did this, @bnjmnm. Perhaps you can walk me through it? 🙏😊Comment #17
bnjmnmThese can stay as-is, this was largely due to my habit of quickly changing the tags to allow ONLY
<p><br>
during repeat manual testing. Adding those tags allows me to continue and enjoy the full functionality of what we're adding here.Comment #18
bnjmnmThe failing tests are all tests expected to fail because the editors being switched from include tags/attributes not currently supported by CKEditor 5. There are existing issues for all of these.
There's undoubtedly additional work to do, but it's also at a good point to pause so we can attend to some of the issues needed for tests here to pass, and a bit of time away from this complex issue will provide some perspective that will make completion easier.
Comment #19
Wim LeersCan confirm.
From
to
thanks to #3222847: <img width height> and #3222851: <cite>.
So merged in those two commits from
1.0.x
and pushed them in 98d127d94d488fb70046e41df55d7781f81151f7.Comment #20
Wim LeersThe remaining tags will be addressed by:
So let's exempt those with explicit deprecation errors and
@todo
s. Did that in b8280230a1d000c9ce05fd2e6087af6280718ea6.That brought down the failures to just
The sole exception is
<span>
. What to do about that one … 🤔 Currently the automatically generated settings (and hence also the upgrade path) will allow thetextPartLanguage
plugin, which in turn will enable<span lang dir>
… which is actually a superset. So this will not result in data loss. But it will result in an additional button being enabled for sites that do have<span>
in their allowed HTML but not the "Language of parts" button in their toolbar. Then again, that is the only way to add<span>
right now. Plus, the goal is to not have data loss. The goal is to have a sensible default upgrade path. That extra button is not harmful at all, and if anything, it improves accessibility — by encouraging content creators to think about other languages.So, while not perfect, I'm going to go ahead and explicitly allow a superset to be generated.
Comment #21
Wim LeersComment #22
Wim LeersSo to do #20, I'm adding the ability to specify the expected superset. i.e. we're going from just
<span>
in the original to<span lang dir>
in the generated/upgraded text format+text editor.Pushed that in 50a02a502ca5a6547e6d3885ea821f013a0875a6 🤞
Comment #23
Wim LeersUgh,
SmartDefaultSettingsTest
is not passing due to the deprecation notices! Removing them. The@todo
s are in there anyway.Comment #24
Wim LeersFinished reviewing. Increased test coverage to ensure there are explicit (and helpful) failures.
I think this is ready to be pushed across the finish line by @bnjmnm!
Comment #25
bnjmnmComment #26
bnjmnmThe final test failures are due to the allowed HTML field not updating with the added toolbar items. The field updates correctly if anything additional is done to trigger an AJAX rebuild (change a plugin setting, move a toolbar item, etc).
Perhaps the changes to the toolbar plugins are happening after the form_alter that gathers the provided tags based on the current plugin conifg? I tried adding a second update of the allowed_html filter settings during the AJAX rebuild in
_update_ckeditor5_html_filter()
. This updates the field value to the tags supported by the current toolbar config, but this happensafter
validation so that's not a good option.It's not immediately clear how/where to implement the rebuild so this doesn't happen but it seems like the sort of thing that is easier to figure out after stepping away for a moment.
Comment #27
Wim Leers#3226011: Introduce CKEditor5PluginConfigurableInterface::getDefaultSettings() would solve https://git.drupalcode.org/project/ckeditor5/-/merge_requests/71/diffs#n.... I think that's a simple issue to do first 🤓
Comment #28
bnjmnmComment #29
Wim LeersMerged in
1.0.x
because #3226011: Introduce CKEditor5PluginConfigurableInterface::getDefaultSettings() was merged.Comment #30
Wim LeersLet me start off by saying this is fantastic work! 🤩👏
I just posted a thorough/comprehensive (well, I reviewed 90%, will do the remaining 10% next) review of the merge request. But there's one thing that I cannot easily capture in there. Hence this comment!
When switching the Standard install profile's
text format (and first allowing<p> <br>
and disabling thefilter_url
andfilter_autop
filters) to use CKEditor 5, I see this:Note that it is not talking about the
,Bold
andItalic
buttons/features! That's because those are pre-configured by\Drupal\ckeditor5\Plugin\Editor\CKEditor5::getDefaultSettings()
— the message only informs the user about the additional buttons/features.Imagine we would change
CKEditor5::getDefaultSettings()
to returnreturn ['toolbar' => ['items' => []]];
. Then this would happen:Is that not much better/more informative? 😊Better still: we should keep
CKEditor5::getDefaultSettings()
unchanged because I do think it's a sensible default. I just think that when the starting point is a pre-existing text format (FilterFormat::isNew() === FALSE
) that has no text editor associated at all (Editor::load($format_id) === NULL
) we should use['toolbar' => ['items' => []]]
as the starting point. That means that for completely new text formats, we still do useCKEditor5::getDefaultSettings()
as it exists today.Comment #31
Wim LeersFollow-up created for that review round I just posted: #3226335: Follow-up for #3216015: allow contrib & custom Drupal modules providing CKEditor 4 plugins to specify their CKEditor 5 equivalents + settings to be migrated.
Comment #32
Wim LeersComment #33
Wim Leers#3226673: API addition: \Drupal\editor\Plugin\EditorPluginInterface::getDefaultSettings() should accept old Editor + Format to generate smart defaults to make the whole
SmartDefaultSettings
thing not an afterthought that we need to bolt on, but something built in to the Text Editor module. It's an obvious addition, and would allow us to remove this unnecessarily confusing & distracting code:Added
@todo
s for this in 997edc912c06ff47703b183e142f584f64224581.Comment #34
Wim LeersThere are two negative consequences of using the
messenger
service directly in\Drupal\ckeditor5\SmartDefaultSettings::computeSmartDefaultSettings()
:drush ckeditor5:audit
output looks like this:restricted_html
to CKEditor 5, you do not only see the fundamental compatibility constraint violation message, but also the messages from the computing of smart defaults:(only the circled message should've been visible)
Just like with the original config validation logic first being unable to convey multiple violation messages, the new smart default settings is unable to return multiple messages — it just "sends them globally".
Created #3226694: Follow-up for #3216015: refactor SmartDefaultSettings to return messages rather than sending them for that.
Meanwhile, we need a work-around at least for point 2, because that is visibly interfering. Point 1 is merely a nuisance at this time.
Comment #35
Wim LeersComment #36
Wim LeersAlso discovered #3226486: Investigate CKE5's GHS plugin rewriting certain user input and #3226478: CKEditor5::getDefaultSettings() has a stale comment and returns invalid settings thanks to this issue!
Comment #37
Wim LeersComment #39
Wim LeersI walked @bnjmnm yesterday night through the changes I'd made yesterday, and described what the remaining problem was with the
restricted_html
test case inSmartDefaultSettingsTest
. That's what all of today's changes were focused on … until I ran into #34. So added a work-around for that and a follow-up issue to solve it better.@bnjmnm and I both believe this is solid, and while it may not be perfect, it certainly represents a vast leap forward — captured in 121 commits and 118 merge request threads over the course of multiple weeks. Merged this so we can keep moving forward! 🚢
Comment #40
Wim LeersRetroactively fixing priority 🤓