Refine ValidKeysConstraintValidator's messages: use #3401883's new Mapping infrastructure

Created on 6 December 2023, 9 months ago
Updated 10 January 2024, 8 months ago

Problem/Motivation

Split off from πŸ“Œ Configuration schema & required keys Fixed .

ℹ️ This MR contains 310 insertions(+), 59 deletions(-) of the 1125 insertions(+), 151 deletions(-) that the MR for πŸ“Œ Configuration schema & required keys Fixed 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 πŸ“Œ Introduce Mapping::getValidKeys(), ::getRequiredKeys() etc. Active landed, a small part of πŸ“Œ Configuration schema & required keys Fixed 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

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A

πŸ“Œ Task
Status

Fixed

Version

11.0 πŸ”₯

Component
ConfigurationΒ  β†’

Last updated 1 day ago

Created by

πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Wim Leers
  • Status changed to Needs review 9 months ago
  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    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:

    In other words: a much more detailed message.

  • Issue was unassigned.
  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    ℹ️ This MR contains 311 insertions(+), 60 deletions(-) of the 1125 insertions(+), 151 deletions(-) that the MR for πŸ“Œ Configuration schema & required keys Fixed 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.

  • Status changed to Needs work 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

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

  • Assigned to Wim Leers
  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    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 πŸ“Œ Configuration schema & required keys Fixed πŸ˜„

    On it :)

  • Issue was unassigned.
  • Status changed to Needs review 9 months ago
  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    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)

  • Status changed to RTBC 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    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.

  • πŸ‡§πŸ‡ͺBelgium borisson_ Mechelen, πŸ‡§πŸ‡ͺ

    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 πŸ› Consistently use "dynamic type name" and "expression" instead of "variable value" in TypedConfigManager's terminology Fixed , 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.

  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    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 πŸ“Œ Configuration schema & required keys Fixed as much as you have 😊 Thank you!

  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Applied all of @phenaproxima's remaining suggestions because πŸ› Consistently use "dynamic type name" and "expression" instead of "variable value" in TypedConfigManager's terminology Fixed landed πŸ₯³

  • Status changed to Needs work 9 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

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

  • Assigned to Wim Leers
  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • Issue was unassigned.
  • Status changed to RTBC 9 months ago
  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    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.

  • Status changed to Needs work 9 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

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

  • Status changed to Needs review 9 months ago
  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Addressed all of @larowlan's feedback 😊

    (And merged in 11.x, which allowed reverting 2 lines πŸ‘)

  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

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

  • Assigned to Wim Leers
  • Status changed to Needs work 9 months ago
  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • Issue was unassigned.
  • Status changed to RTBC 9 months ago
  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Based on @larowlan's feedback, I reverted a few lines from the test coverage additions (because they belong in πŸ“Œ Configuration schema & required keys Fixed , 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.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Committed c980ece and pushed to 11.x. Thanks!

  • Status changed to Fixed 9 months ago
    • alexpott β†’ committed c980ece6 on 11.x
      Issue #3406478 by Wim Leers, phenaproxima, borisson_, alexpott, larowlan...
  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024