Problem/Motivation
Split off from #3364108: Configuration schema & required keys.
ℹ️ This MR contains 310 insertions(+), 59 deletions(-) of the 1125 insertions(+), 151 deletions(-) that the MR for #3364108: Configuration schema & required keys contains. IOW: this shrinks the other MR by ~30%. The other MR can be layered cleanly on top of this one; not a single line added there would need to change.
Now that #3401883: Introduce Mapping::getValidKeys(), ::getRequiredKeys() etc. landed, a small part of #3364108: Configuration schema & required keys can actually land ahead of the bigger/more contentious change: the ability to provide more precise validation error messages for when keys are invalid due to a dynamic type (a "variable value" in the config schema type).
For example:
block.block.*:
type: config_entity
label: 'Block'
mapping:
…
plugin:
type: string
label: 'Plugin'
constraints:
PluginExists:
manager: plugin.manager.block
interface: Drupal\Core\Block\BlockPluginInterface
settings:
type: block.settings.[%parent.plugin]
Steps to reproduce
N/A
Proposed resolution
- Before
-
use_site_logo' is not a supported key. - After
-
use_site_slogan' is an unknown key because plugin is system_powered_by_block (see config schema type block.settings.*).
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
Issue fork drupal-3406478
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 #3
wim leersThe updated test coverage should fail like this:
So:
In other words: a much more detailed message.
Comment #4
wim leersℹ️ This MR contains
311 insertions(+), 60 deletions(-)of the1125 insertions(+), 151 deletions(-)that the MR for #3364108: Configuration schema & required keys contains.IOW: this shrinks the other MR by ~30%. The other MR can be layered cleanly on top of this one; not a single line added there would need to change.
Comment #5
phenaproximaThis looks good and makes sense. I have a fair number of small comments (as I usually do), in the hope of improving clarity, but overall I find this close to RTBC-able..
Comment #6
wim leersI would hope so, since you've already reviewed exactly this code multiple times in #3364108: Configuration schema & required keys 😄
On it :)
Comment #7
wim leersSome good questions about code clarity, I hope I made you proud, @phenaproxima 😄 (This ended up taking 1.5 hour 🤯 — naming & explaining can be time-consuming :D)
Comment #8
phenaproximaI don't think I have any real problems with this. The really complicated and potentially confusing stuff is now heavily commented with examples, the variable names are probably about as as clear as they can be, and the test coverage makes sense too. This is a worthy improvement to the ValidKeys constraint and will be really helpful for DX.
We could go back-and-forth on this for longer if we wanted to, but we've got bigger fish to fry. Ship it.
Comment #9
borisson_When this issue was opened earlier today, it was my plan to take some time after to work to look into this, even though I already reviewed the parent MR a couple of times.
It looks like @phenaproxima and @Wim Leers have already taken the fun out of the review, since it is already improved over the orignal with much more/better comments and better naming.
If this lands before #3406487: Consistently use "dynamic type name" and "expression" instead of "variable value" in TypedConfigManager's terminology, we have to make sure to apply the suggestions that @phenaproxima made here to that one, but that should be easy enough to do.
Feels like all I can say is that I agree with the rtbc in #8.
Comment #10
wim leers🤣
You've both already heavily influenced this MR, by reviewing #3364108: Configuration schema & required keys as much as you have 😊 Thank you!
Comment #11
wim leersApplied all of @phenaproxima's remaining suggestions because #3406487: Consistently use "dynamic type name" and "expression" instead of "variable value" in TypedConfigManager's terminology landed 🥳
Comment #12
alexpottI think we need to handle dprecating the public API rather than just removing it.
Comment #13
wim leersComment #14
wim leersRestored
ValidKeysConstraint::getAllowedKeys()method per @alexpott's review. Since this is just trivially moving logic from one spot to another, there's 0 functional changes and tests are still passing: back to RTBC.Comment #15
larowlanLeft some questions on the MR, only one of them is important
Comment #16
wim leersAddressed all of @larowlan's feedback 😊
(And merged in
11.x, which allowed reverting 2 lines 👍)Comment #17
wim leersI merged in upstream in #16. This caused a failure in
\Drupal\Tests\block\Kernel\Migrate\d6\MigrateBlockTestdue to #3371219: Remove forum from block migration tests (landed 2 days ago), whose expected messages become more precise thanks to this issue. 👍 Trivial fix!Comment #18
wim leersComment #19
wim leersBased on @larowlan's feedback, I reverted a few lines from the test coverage additions (because they belong in #3364108: Configuration schema & required keys, which is blocked by this issue, plus Lee marked the MR thread as resolved himself), added a typehint and tweaked an
assert().The actual changes are so minor that I feel a re-self-RTBC is reasonable.
Comment #20
alexpottCommitted c980ece and pushed to 11.x. Thanks!
Comment #22
wim leersYay! Next up: #3364108-90: Configuration schema & required keys 😊