Problem/Motivation
This is text format schema (removed some parts for readability):
filter.format.*:
type: config_entity
mapping:
name:
type: required_label
(...)
filters:
type: sequence
orderby: key
sequence:
type: filter
Each filter is of type filter:
filter:
type: mapping
mapping:
id:
type: string
(...)
settings:
type: filter_settings.[%parent.id]
Each filter's settings is of type filter_settings.<filter_plugin_id>, defaulting to filter_settings.*
But here comes the weirdness: Each filter_settings.<filter_plugin_id> is again of type filter (except filter_settings.* which correctly goes to a sequence)
For instance:
filter_settings.filter_html:
type: filter
mapping:
...
I think each filter_settings.<filter_plugin_id> should be of type mapping
Proposed resolution
Fix all core schemas to filter_settings.<filter_plugin_id>, including filter_settings.*
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
Core filter_settings.<filter_plugin_id> schemas have now correct mapping type
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3404431-8-suggested-interdiff.txt | 1.27 KB | wim leers |
| #7 | Screenshot 2023-11-28 at 11.51.49 AM.png | 1.48 MB | wim leers |
Issue fork drupal-3404431
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:
- 3404431-filter-settings-schema
changes, plain diff MR !5559
Comments
Comment #2
claudiu.cristeaFix title
Comment #4
claudiu.cristeaComment #5
wim leers+1!
This is technically a duplicate of #3401837: Add basic validation to config schema definitions, but there I'm trying to add automatic detection of this very problem to ensure it can happen never again (reviews + help appreciated 🤓).
But that issue is likely to take a long time to land. I think it makes sense to fix core's schema regardless of deeper configuration schema system DX/architecture improvements 👍
Comment #6
claudiu.cristeaI came here from #3404070: Slick filter schema is incomplete (weird issue there)
I was thinking that it's good to have a base schema for a particular *kind* of configs
Comment #7
wim leersThe change of
filter.settings.*fromtype: sequencetotype: mappingimplies all keys must now be defined.Which means every
@Filterplugin with settings now MUST definefilter.settings.<PLUGIN ID>if they want toConsequence is this validation error now appearing for (all?) CKEditor 5 functional JS tests:
But why?
\Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5TestBase::createNewTextFormat()uses the UI to generate a new text format, resulting infilters.filter_urlbeing set to:settingsvalue complies withtype: filter_settings.filter_url👍type: filter, which it does NOT:idandproviderare missing. That's why config schema was unable to resolvetype: filter_settings.[%parent.id]tofilter_settings.filter_urland instead fell back tofilter_settings.*😱Comment #8
wim leersAFAICT we have two choices:
filter_settings.*, to allow it to continue to accept arbitrary garbage values\Drupal\filter\FilterFormatFormBaseBetter to fix all the broken things that are connected IMO, so attached a suggested interdiff that AFAICT should fix it 🤞
Comment #9
claudiu.cristeaI went with #8.2 as it avoids adding any arbitrary sequence but used fields of type
value. Let's see the botComment #10
claudiu.cristeaFixing IS
Comment #11
wim leersWow, that worked! 😃
Comment #12
wim leersComment #13
wim leersActually … I think this needs an update path + test.
My suggestion in #8 only works because it affects new text formats, and that happens to be the only thing being tested.
We need to ensure everything is in a consistent state, which means making sure all
FilterFormatconfig entities contain the missing data. Fortunately, it's simple enough to populate those 2 property paths for each filter in each format.Thanks to
filter_post_update_sort_filters()and\Drupal\filter\Entity\FilterFormat::preSave()in #3017054: Consistently sort filter formats to simplify config exports there is a very recent example in the same area 👍 Back to you, @claudiu.cristea 😊Comment #14
borisson_There are a couple of remaining failures in the javascript test coverage, they seem to be related (as they fail in ckeditor / filter things).
But I agree with @Wim Leers, this issue is great!
Removing tags that have been implemented already.
Comment #15
wim leersDebugging the failing Functional JS CKEditor 5 tests…
Comment #16
wim leerse2ac97aff5ebcf0b7a226d1749036b8fd06f2c98 caused this regression. We still need the changes in
FilterFormatFormBasethat I proposed in #8.The reason:
FilterFormat::preSave()does not get called until after validation happens.Comment #17
wim leers@claudiu.cristea independently discovered and diagnosed this issue after I opened the broader scoped #3401837: Add basic validation to config schema definitions to forever detect and prevent this bug pattern from getting reintroduced.
I only helped with debugging the failing CKEditor 5 JS tests (see #8 for details) and provided a trivial suggestion … that happened to work on the first try :D
@claudiu.cristea also provided an update path + tests, to automatically fix all of
filter.format.*config objects on all sites, to add the missing information (id+provider).This looks excellent, so RTBC'ing 😊
Comment #18
quietone commentedI'm triaging RTBC issues. I read the IS, the comments and the MR. I didn't find any unanswered questions.
I left a comment on the MR. I would have made the change myself but maybe someone here has a better one line summary.
And, correct me if I am wrong but I also think it prudent to have a change record.
Sorry, but back to NW for two items.
Comment #19
claudiu.cristea@quietone, thank you. I’ve applied the suggestion but I don’t see the need for a CR, we’re fixing here a bug. No idea what I could write in a CR
Comment #20
longwaveAre we sure we don't need a change record?
If contrib or custom code that adds a filter setting schema has made the same mistake, we need them to update from
filtertomapping, no?And if existing code has made that mistake, will there be any side effects anywhere if we commit this?
Comment #21
wim leersYes, they should all change. You're right that they likely all copied the wrong pattern from Drupal core. CR to announce this: https://www.drupal.org/node/3419181.
No, zero side effects in production. This only:
To prevent such circular config schema types from being introduced accidentally in the future in core/contrib, I created #3401837: Add basic validation to config schema definitions.
Comment #22
longwaveThanks for the explanation.
Committed d8c4e4c and pushed to 11.x. Thanks!
Also published the change record.
Comment #25
wim leersThanks so much!
Pushed both unblocked issues forward:
Comment #32
quietone commentedAdding credit for duplicate, #2472927: Remove generic sequence schema for filter plugins,