Add validation constraints to olivero.settings

Created on 20 October 2023, 8 months ago
Updated 26 February 2024, 4 months ago

Problem/Motivation

Olivero's settings have 3 property paths that are not yet validatable:

$ vendor/bin/drush config:inspect --filter-keys=olivero.settings --detail --list-constraints --fields=key,validatability,constraints
โžœ  ๐Ÿค– Analyzingโ€ฆ

 ------------------------------------------------------------- ------------- ------------------------------------------ 
  Key                                                           Validatable   Validation constraints                    
 ------------------------------------------------------------- ------------- ------------------------------------------ 
  olivero.settings                                              83%           ValidKeys: '<infer>'                      
                                                                              RequiredKeys: '<infer>'                   
   olivero.settings:                                            Validatable   ValidKeys: '<infer>'                      
                                                                              RequiredKeys: '<infer>'                   
   olivero.settings:_core                                       Validatable   ValidKeys:                                
                                                                                - default_config_hash                   
                                                                              RequiredKeys: '<infer>'                   
   olivero.settings:_core.default_config_hash                   Validatable   NotNull: {  }                             
                                                                              Regex: '/^[a-zA-Z0-9\-_]+$/'              
                                                                              Length: 43                                
                                                                              โ†ฃ PrimitiveType: {  }                     
   olivero.settings:base_primary_color                          NOT           โš ๏ธ  @todo Add validation constraints here  
   olivero.settings:favicon                                     Validatable   ValidKeys: '<infer>'                      
                                                                              RequiredKeys: '<infer>'                   
   olivero.settings:favicon.use_default                         Validatable   โ†ฃ PrimitiveType: {  }                     
   olivero.settings:features                                    Validatable   ValidKeys: '<infer>'                      
                                                                              RequiredKeys: '<infer>'                   
   olivero.settings:features.comment_user_picture               Validatable   โ†ฃ PrimitiveType: {  }                     
   olivero.settings:features.comment_user_verification          Validatable   โ†ฃ PrimitiveType: {  }                     
   olivero.settings:features.favicon                            Validatable   โ†ฃ PrimitiveType: {  }                     
   olivero.settings:features.node_user_picture                  Validatable   โ†ฃ PrimitiveType: {  }                     
   olivero.settings:logo                                        Validatable   ValidKeys: '<infer>'                      
                                                                              RequiredKeys: '<infer>'                   
   olivero.settings:logo.use_default                            Validatable   โ†ฃ PrimitiveType: {  }                     
   olivero.settings:mobile_menu_all_widths                      NOT           โš ๏ธ  @todo Add validation constraints here  
   olivero.settings:site_branding_bg_color                      NOT           โš ๏ธ  @todo Add validation constraints here  
   olivero.settings:third_party_settings                        Validatable   ValidKeys: '<infer>'                      
                                                                              RequiredKeys: '<infer>'                   
   olivero.settings:third_party_settings.shortcut               Validatable   ValidKeys: '<infer>'                      
                                                                              RequiredKeys: '<infer>'                   
   olivero.settings:third_party_settings.shortcut.module_link   Validatable   โ†ฃ PrimitiveType: {  }                     
 ------------------------------------------------------------- ------------- ------------------------------------------ 

Steps to reproduce

  1. Get a local git clone of Drupal core 11.x.
  2. composer require drupal/config_inspector โ€” or manually install https://www.drupal.org/project/config_inspector/releases/2.1.5 โ†’ or newer (which supports Drupal 11!)
  3. composer require drush/drush
  4. vendor/bin/drush config:inspect --filter-keys=olivero.settings --detail --list-constraints

Proposed resolution

Add validation constraints to:

  1. base_primary_color
  2. mobile_menu_all_widths
  3. site_branding_bg_color

This requires looking at the existing code and admin UI (if any) to understand which values could be considered valid. Eventually this needs to be reviewed by the relevant subsystem maintainer.

For examples, search *.schema.yml files for the string constraints: ๐Ÿ˜Š

Reach out to @borisson_ or @wimleers in the #distributions-and-recipes.

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

More validation ๐Ÿš€

Release notes snippet

None.

๐Ÿ“Œ Task
Status

Fixed

Version

11.0 ๐Ÿ”ฅ

Component
Oliveroย  โ†’

Last updated 1 day ago

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Wim Leers
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • First commit to issue fork.
  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom Eli-T Manchester

    Initial commit adds validation for color_hex base type, and hence covers base_primary_color.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom Eli-T Manchester
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom Eli-T Manchester
  • 25:50
    23:15
    Running
  • Status changed to Needs review 8 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom Eli-T Manchester
  • Pipeline finished with Success
    8 months ago
    Total: 567s
    #35017
  • 56:30
    48:19
    Running
  • Pipeline finished with Success
    8 months ago
    Total: 558s
    #35184
  • Status changed to RTBC 8 months ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain penyaskito Seville ๐Ÿ’ƒ, Spain ๐Ÿ‡ช๐Ÿ‡ธ, UTC+2 ๐Ÿ‡ช๐Ÿ‡บ

    All feedback has been resolved with @see comments.

    Before:
    olivero.settings 83%

    After:
    olivero.settings 100%

    I validated that the choices described in the schema constraints are the ones available at the form.
    This looks great to me.

    A doubt that I have is:
    If e.g. I had to alter a form for adding an extra option in olivero settings form in my custom module, I probably need to implement hook_config_schema_info_alter to alter that constraint. I'm not sure if we have already docs/change records including that, but probably this is something worth to document.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium borisson_ Mechelen, ๐Ÿ‡ง๐Ÿ‡ช

    Changes look great, rtbc ++

    If e.g. I had to alter a form for adding an extra option in olivero settings form in my custom module, I probably need to implement hook_config_schema_info_alter to alter that constraint. I'm not sure if we have already docs/change records including that, but probably this is something worth to document.

    This is a general issue with a lot of the validation constraints we are adding, I agree this makes some things more difficult.
    I'm not sure how we can make this more strict and also keep the freedom the add extra options there. @Wim Leers might have an idea.

  • last update 8 months ago
    30,426 pass
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom Eli-T Manchester
  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Sorry, I spotted a few small problems ๐Ÿ˜…

    If e.g. I had to alter a form for adding an extra option in olivero settings form in my custom module, I probably need to implement hook_config_schema_info_alter to alter that constraint. I'm not sure if we have already docs/change records including that, but probably this is something worth to document.

    +

    I'm not sure how we can make this more strict and also keep the freedom the add extra options there. @Wim Leers might have an idea.

    This is another reason that using the Choice constraint is so great: that makes it easy to declaratively add additional valid choices :)

  • Status changed to Postponed 8 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom Eli-T Manchester

    Have created โœจ Allow three character hex colour definitions in Olivero settings Active to discuss making Olivero consistent with Image module's colour validation.

    Postponing this issue based on the outcome of that one.

  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Whilst 3 character HEX codes are a thing, Olivero does not currently accept them

    Well in that case โ€ฆ we don't need to wait for that! ๐Ÿ˜Š

    What matters is that the validation constraints match the expectations of the logic. ๐Ÿ‘

    Marking for that leading : in the message.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom Eli-T Manchester

    @wim-leers I think this still should be postponed, because this MR adds validation to the core config type of colour-hex.

    That is used in two different places with different logic. Therefore we can't match the expectations of the logic until they are synchronised in โœจ Allow three character hex colour definitions in Olivero settings Active .

    If we proceeded as-is with this change, config that used three character codes in image style configuration would suddenly become invalid.

  • last update 8 months ago
    30,427 pass
  • Pipeline finished with Success
    8 months ago
    Total: 682s
    #36740
  • Status changed to Postponed 8 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Oh, that makes sense โ€” I didn't realize that ๐Ÿ˜…! Thanks, @Eli-T ๐Ÿ˜Š

  • Status changed to Needs work 6 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    This now needs the FullyValidatable constraint to be added to olivero.settings. See https://www.drupal.org/node/3404425 โ†’ .

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States phenaproxima Massachusetts

    Blocker's in!

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Note: we should update this to use #config_target in Olivero's settings form (which only became usable after that MR was originally created, see the CR at https://www.drupal.org/node/3373502 โ†’ ), and remove the validation logic from the form.

  • Pipeline finished with Canceled
    6 months ago
    Total: 333s
    #76783
  • Pipeline finished with Failed
    6 months ago
    Total: 482s
    #76786
  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium borisson_ Mechelen, ๐Ÿ‡ง๐Ÿ‡ช

    I've removed the FullyValidatable from olivero, judging from the test failures, we first need to take care of theme_settings, but I don't think this issue needs to wait for that.

  • Pipeline finished with Success
    6 months ago
    #76859
  • Status changed to RTBC 5 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    It's a bit odd that mobile_menu_all_widths is type: integer. I think type: boolean would make more sense. But that'd be both unnecessary and scope creep.

    I've removed the FullyValidatable from olivero, judging from the test failures, we first need to take care of theme_settings, but I don't think this issue needs to wait for that.

    I first wanted to disagree ๐Ÿ˜‡๐Ÿค“ But then I looked at the test failures and was forced to agree with you! ๐Ÿ˜„ Once type: theme_settings is fully validatable, we'll indeed be able to mark olivero.settings as fully validatable too ๐Ÿ‘

  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Oops! I forgot the #config_target bit I mentioned in #20, and which convinced @longwave to land the blocker at โœจ Allow three character hex colour definitions in Olivero settings Active ๐Ÿ˜…

    This MR should therefore update olivero_form_system_theme_settings_alter() to use #config_target to use constraint-based validation. Which also means we should be able to remove olivero_theme_settings_validate() here.

  • Pipeline finished with Success
    5 months ago
    #78220
  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States phenaproxima Massachusetts
  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Since this is the first theme settings form using this, and

    Colors must be 7-character string specifying a color hexadecimal format.
    

    does not occur in any test, let's add a functional test to prove that the validation error correctly appears. That will also help with converting type: theme_settings to use validation constraints (especially given Olivero is the default front end theme) ๐Ÿ‘

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Akhil Babu Chengannur

    Akhil Babu โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Canceled
    5 months ago
    Total: 27s
    #79209
  • Pipeline finished with Success
    5 months ago
    Total: 605s
    #79210
  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Akhil Babu Chengannur

    I have updated the regex and added a test to valiate the hex codes.

  • Pipeline finished with Failed
    5 months ago
    Total: 161s
    #79292
  • Pipeline finished with Success
    5 months ago
    Total: 568s
    #79294
  • Status changed to RTBC 5 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Excellent work here, @Akhil Babu! ๐Ÿ˜Š Thanks for writing those tests!

    There's one thing to nitpick (the assertion for the message could be more precise and hence more robust), but that's IMHO not commit-blocking. ๐Ÿ‘

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Akhil Babu Chengannur

    Thanks @Wim Leers.
    Updated the method but now there is a strange Nightwatch test failure.
    https://git.drupalcode.org/issue/drupal-3395555/-/jobs/661127

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    That looks like a random test failure โ€” chromedriver-powered tests are notoriously fickle.

    Re-running the Nightwatch tests โ€” I expect those to pass now.

  • Pipeline finished with Success
    5 months ago
    Total: 6970s
    #79694
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Turns out that single failure was a regression in Drupal core, and the commit has since been reverted: #3413665-10: Enable modules through Nightwatch API when not testing module enabling โ†’ .

    Green CI again! ๐Ÿ‘

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    For type: theme_settings: ๐Ÿ“Œ Add validation constraints to `type: theme_settings` Active .

  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    Nearly committed this but actually have one question on the MR.

  • Status changed to RTBC 5 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    ๐Ÿ“

  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    OK those are good reasons, but let's add them to the comment.

  • Status changed to RTBC 5 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Re-RTBC'ing โ€” I didn't touch this MR, I was only a reviewer. I provided the rationale for me RTBC'ing it despite the thing @catch rightfully questioned, and added that as a comment ๐Ÿ‘

  • Pipeline finished with Failed
    5 months ago
    #91337
    • catch โ†’ committed 99804f40 on 11.x
      Issue #3395555 by Eli-T, Akhil Babu, borisson_, Wim Leers, phenaproxima...
  • Status changed to Fixed 5 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    Committed/pushed to 11.x, thanks!

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Yay!

    This inspired a follow-up ๐Ÿค“ โ€” see [#3420770.

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

Production build 0.69.0 2024