Problem/Motivation
Discovered while working on #3228334: Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object.
#3216015: Generate CKEditor 5 configuration based on pre-existing text format configuration introduced SmartDefaultSettings, to compute upgrade paths automatically.
Right now, there is a single ckeditor5_alignment plugin with 5 toolbar items (align left, align center, align right, justify — plus a dropdown providing access to all 5), with the following plugin definition:
ckeditor5_alignment:
…
drupal:
…
elements:
- <$block class="text-align-left text-align-center text-align-right text-align-justify">
This means that any Drupal 8|9 text format configured to allow one or more of those classes will get all 5 of those toolbar items configured in CKEditor 5 and will have all four of those attribute values allowed.
Steps to reproduce
Update from a text format using CKEditor with <p class="text-align-center"> in the list of allowed HTML tags of filter_html.
Proposed resolution
In order for SmartDefaultSettings to be able to generate more precise CKEditor 5 configuration, we need to split up this plugin definition; so we know that for example the alignment:center button only generates <$block class="text-align-center">, so that it can automatically only allow that plugin.
Remaining tasks
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3259179-2.patch | 2.2 KB | wim leers |
| #2 | 3259179-after-3259174-do-not-test.patch | 4.37 KB | wim leers |
Comments
Comment #2
wim leersThis patch could land right away — it's an uncontroversial splitting of an existing CKEditor 5 plugin definition. At least, if I'm right, and this will not cause any test failures 🤞
I've also shown what additions would be necessary if this lands after #3259174: Add missing CKE5 SmartDefaultSettings test coverage (wildcard tag with unsupported attribute).
Comment #3
lauriiiIt makes sense to me that users might want to limit what options are available for aligning the text. The solution is straight forward and works for me. I guess an alternative approach would be to allow configuring which options are available in the dropdown, but what's here works for me.
Comment #4
bnjmnmReviewing this made it apparent that the alignment controls being buttons AND dropdowns should be addressed, but not in this scope. Created #3259593: Alignment being available as separate buttons AND in dropdown is confusing as a followup.
Comment #5
bnjmnmThis results in the addition of all 4 text-align-x classes added to "allowed tags", even if a single button is chosen. Removing the merge key use address that. That leads me to wonder if it's expected behavior and I did not correctly interpret the issue summary.
In Proposed Solution I see
so that leads me to believe the expectation is to add the classes per-button, which is isn't currently doing, so this either needs the patch changed or the issue summary updated to make the expected result a little clearer.
Comment #6
wim leers#4++ — thanks for creating that!
#5: No, it does not. YAML syntax is weird. The
<<operator inherits everything from the referenced variable except for explicitly defined keys. It's basically the YAML equivalent of PHP's+operator on arrays. Copy/paste it into https://yamlvalidator.com/ to observe the behavior.That's not what I see — neither in the UI, nor if I skip the YAML validation logic above and instead inspect it using the plugin definition:
Comment #10
bnjmnmWhat I ran into #5 surprised me as well and deviated from my understanding of the
<<operator. Whatever the circumstances were that caused the odd behavior reported in #5, I was unable to reproduce despite considerable attempts do to so.This is a very straightforward and welcome change that is behaving exactly as I'd expect it to, so I'm committing to 9.4.x, 10.0.x, as well as 9.3.x since it is a safe change to an experimental module that adds important upgrade path functionality.
Comment #12
dom. commentedThis issue introduced "regression" in the sense that is crashes the CKE5 when multiple alignments buttons are activated to the toolbar.
See #3273510: CKEditor 5 crash when multiple alignment buttons are activated due to duplicate configuration