Problem/Motivation
I am working on a site which makes heavy use of the styles dropdown as part of the content authoring experience. Once config is exported, storing all of these styles in a string causes unreadable diffs and frequent merge conflicts.
My config looks something like:
stylescombo:
styles: "h2.section-title--large|Section title\r\nh2.page-title--tick|Success title\r\n... # And so on for quite some time..."
Proposed resolution
Create a schema for storing these settings which breaks out the stylecombo into a sequence. Proposed schema would look something like:
ckeditor.plugin.stylescombo:
type: mapping
label: 'Styles dropdown'
mapping:
styles:
type: sequence
label: 'List of styles'
sequence:
type: mapping
mapping:
style:
type: string
label: 'Style'
label:
type: label
label: 'Label'
Which would transform the above into something like:
stylescombo:
styles:
-
style: 'h2.section-title--large'
label: 'Section title'
-
style: 'h2.page-title--tick'
label: 'Success title'
This also makes these labels translatable, although I admit that came to me as an afterthought while writing the schema.
Remaining tasks
Validate this is worth working on.
Write a patch.
User interface changes
None.
API changes
None.
Data model changes
Config schema changes.
Comment | File | Size | Author |
---|---|---|---|
#12 | 2871351-stylescombo-schema-12.patch | 15.52 KB | Sam152 |
#12 | interdiff.txt | 4.65 KB | Sam152 |
#10 | 2871351-stylescombo-schema-10.patch | 15.63 KB | Sam152 |
#10 | interdiff.txt | 2.32 KB | Sam152 |
#9 | interdiff.txt | 6.5 KB | Sam152 |
Comments
Comment #2
Wim LeersThis totally makes sense! I see no reason not to do this, it's better on all fronts. The current code is pre-D8 thinking.
Thanks for filing this :) Any chance you can work on a patch? I'll provide reviews!
Comment #3
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedHappy to work on a patch, my biggest concern is it somehow being a BC break. Not sure if config schema is directly an API.
Comment #4
Wim LeersThis configuration is likely only ever updated through the UI. The UI will remain the same. We've changed the structure of configuration in the past. What matters most is an update path, which is totally feasible.
So: I'm not concerned :)
I checked https://www.drupal.org/core/d8-bc-policy, and it doesn't mention or at all. Besides, we've done this sort of thing in the past. And much more complex ones. For example: #2308745: Remove rest.settings.yml, use rest_resource config entities. So I'm 99% certain this will be fine.
Comment #5
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedCool, thanks for validating this idea and approach.
Comment #6
Wim LeersOne suggestion. Instead of:
using this would be clearer I think:
Comment #7
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedInitial pass over this. There was already a structured representation of the data that was prepared and sent to the client for ckeditor. Using the same schema means if we configured or used the ckeditor feature in a different way in the future, the schema would support it already.
Comment #9
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedTest fixes.
Comment #10
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedFew more tidy ups.
Comment #11
Wim LeersGreat work here!
I think it'd be more logical to break out of this loop early when the editor is not
ckeditor
?Nice :)
This matches the terminology in http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-stylesSet — so +1! :)
This is a behavior change that we can avoid.
i.e. if there was no stylescombo setting, then we would return the empty array. With these changes, that's no longer the case.
Let's bring back the old behavior, to minimize change.
Let's make this method
static
, because it does not depend on any object property.This is asserting the structure after the update — great! But it'd be good to also assert the structure before the update. i.e. to assert that it's a string.
Comment #12
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThanks for the review!
1. Makes sense.
4. Good catch.
5. I almost never use this pattern, but makes total sense.
6. Added.
Comment #23
quietone CreditAttribution: quietone at PreviousNext commentedCKEditor has been removed from core, CKEditor 4 is removed from Drupal Core in 10.0.0