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

Command icon 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

Wim Leers created an issue. See original summary.

wim leers’s picture

Issue summary: View changes
Status: Active » Needs review

The updated test coverage should fail like this:

Testing /Users/wim.leers/core/core/tests/Drupal/KernelTests/Core/TypedData
.F..                                                                4 / 4 (100%)

Time: 00:04.529, Memory: 10.00 MB

There was 1 failure:

1) Drupal\KernelTests\Core\TypedData\ValidKeysConstraintValidatorTest::testUnknownKeys
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
 Array &0 (
-    0 => ''use_site_logo' is an unknown key because plugin is system_powered_by_block (see config schema type block.settings.*).'
-    1 => ''use_site_name' is an unknown key because plugin is system_powered_by_block (see config schema type block.settings.*).'
-    2 => ''use_site_slogan' is an unknown key because plugin is system_powered_by_block (see config schema type block.settings.*).'
+    0 => ''use_site_logo' is not a supported key.'
+    1 => ''use_site_name' is not a supported key.'
+    2 => ''use_site_slogan' is not a supported key.'
 )

So:

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.*).

In other words: a much more detailed message.

wim leers’s picture

Assigned: wim leers » Unassigned
Issue summary: View changes

ℹ️ This MR contains 311 insertions(+), 60 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.

phenaproxima’s picture

Status: Needs review » Needs work

This 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..

wim leers’s picture

Assigned: Unassigned » wim leers

This 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..

I would hope so, since you've already reviewed exactly this code multiple times in #3364108: Configuration schema & required keys 😄

On it :)

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs work » Needs review

Some 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)

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

borisson_’s picture

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.

wim leers’s picture

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.

🤣

You've both already heavily influenced this MR, by reviewing #3364108: Configuration schema & required keys as much as you have 😊 Thank you!

wim leers’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think we need to handle dprecating the public API rather than just removing it.

wim leers’s picture

Assigned: Unassigned » wim leers
wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs work » Reviewed & tested by the community

Restored 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.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Left some questions on the MR, only one of them is important

wim leers’s picture

Status: Needs work » Needs review

Addressed all of @larowlan's feedback 😊

(And merged in 11.x, which allowed reverting 2 lines 👍)

wim leers’s picture

I merged in upstream in #16. This caused a failure in \Drupal\Tests\block\Kernel\Migrate\d6\MigrateBlockTest due to #3371219: Remove forum from block migration tests (landed 2 days ago), whose expected messages become more precise thanks to this issue. 👍 Trivial fix!

wim leers’s picture

Assigned: Unassigned » wim leers
Status: Needs review » Needs work
wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs work » Reviewed & tested by the community

Based 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.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed c980ece and pushed to 11.x. Thanks!

  • alexpott committed c980ece6 on 11.x
    Issue #3406478 by Wim Leers, phenaproxima, borisson_, alexpott, larowlan...
wim leers’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.