Add validation constraints to search.page.*

Created on 21 June 2024, 8 months ago
Updated 17 July 2024, 7 months ago

Problem/Motivation

Search page config entity is not yet fully validatable:

.vendor/bin/drush config:inspect --filter-keys=search.page.user_search --detail --list-constraints
โžœ  ๐Ÿค– Analyzingโ€ฆ

 Legend for Data: 
  โœ…โ“  โ†’ Correct primitive type, detailed validation impossible.
  โœ…โœ…  โ†’ Correct primitive type, passed all validation constraints.
 ---------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
  Key                                                  Status    Validatable   Data   Validation constraints                                                                       
 ---------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
  search.page.user_search                              Correct   80%           โœ…โ“   ValidKeys: '<infer>'                                                                         
   search.page.user_search:                            Correct   Validatable   โœ…โœ…   ValidKeys: '<infer>'                                                                         
   search.page.user_search:_core                       Correct   Validatable   โœ…โœ…   ValidKeys:                                                                                   
                                                                                        - default_config_hash                                                                      
   search.page.user_search:_core.default_config_hash   Correct   Validatable   โœ…โœ…   NotNull: {  }                                                                                
                                                                                      Regex: '/^[a-zA-Z0-9\-_]+$/'                                                                 
                                                                                      Length: 43                                                                                   
                                                                                      โ†ฃ PrimitiveType: {  }                                                                        
   search.page.user_search:configuration               Correct   NOT           โœ…โ“   โŒ @todo Add validation constraints to ancestor type: search.plugin.user_search              
   search.page.user_search:dependencies                Correct   Validatable   โœ…โœ…   ValidKeys: '<infer>'                                                                         
   search.page.user_search:dependencies.module         Correct   NOT           โœ…โ“   โŒ @todo Add validation constraints to ancestor type: config_dependencies                    
   search.page.user_search:dependencies.module.0       Correct   Validatable   โœ…โœ…   NotBlank: {  }                                                                               
                                                                                      ExtensionName: {  }                                                                          
                                                                                      ExtensionExists: module                                                                      
                                                                                      โ†ฃ PrimitiveType: {  }                                                                        
   search.page.user_search:id                          Correct   Validatable   โœ…โœ…   Regex:                                                                                       
                                                                                        pattern: '/^[a-z0-9_]+$/'                                                                  
                                                                                        message: 'The %value machine name is not valid.'                                           
                                                                                      Length:                                                                                      
                                                                                        max: 166                                                                                   
                                                                                      โ†ฃ PrimitiveType: {  }                                                                        
   search.page.user_search:label                       Correct   Validatable   โœ…โœ…   Regex:                                                                                       
                                                                                        pattern: '/([^\PC])/u'                                                                     
                                                                                        match: false                                                                               
                                                                                        message: 'Labels are not allowed to span multiple lines or contain control characters.'    
                                                                                      NotBlank: {  }                                                                               
                                                                                      โ†ฃ PrimitiveType: {  }                                                                        
   search.page.user_search:langcode                    Correct   Validatable   โœ…โœ…   NotNull: {  }                                                                                
                                                                                      Choice:                                                                                      
                                                                                        callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'  
                                                                                      โ†ฃ PrimitiveType: {  }                                                                        
   search.page.user_search:path                        Correct   NOT           โœ…โ“   โš ๏ธ  @todo Add validation constraints to config entity type: search.page.*                    
   search.page.user_search:plugin                      Correct   Validatable   โœ…โœ…   PluginExists:                                                                                
                                                                                        manager: plugin.manager.search                                                             
                                                                                        interface: Drupal\search\Plugin\SearchInterface                                            
                                                                                      โ†ฃ PrimitiveType: {  }                                                                        
   search.page.user_search:status                      Correct   Validatable   โœ…โœ…   โ†ฃ PrimitiveType: {  }                                                                        
   search.page.user_search:uuid                        Correct   Validatable   โœ…โœ…   Uuid: {  }                                                                                   
                                                                                      โ†ฃ PrimitiveType: {  }                                                                        
   search.page.user_search:weight                      Correct   Validatable   โœ…โœ…   Range:                                                                                       
                                                                                        min: -2147483648                                                                           
                                                                                        max: 2147483647                                                                            
                                                                                      FullyValidatable: null                                                                       
                                                                                      โ†ฃ 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=search.page.user_search --detail --list-constraints

Proposed resolution

Add validation constraints to missing properties.

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 #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
Searchย  โ†’

Last updated 10 days ago

  • Maintained by
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States @pwolanin
Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia narendraR Jaipur, India

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

Merge Requests

Comments & Activities

  • Issue created by @narendraR
  • Merge request !8477Made fullyvalidatable โ†’ (Open) created by narendraR
  • Pipeline finished with Failed
    8 months ago
    Total: 719s
    #204438
  • Pipeline finished with Success
    8 months ago
    Total: 561s
    #204610
  • Status changed to Needs review 8 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia narendraR Jaipur, India
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia vinmayiswamy

    Hi @narendraR,

    Thanks for the MR. Iโ€™ve tested MR 8477 on Drupal 11.x.
    The MR applied cleanly.

    Testing steps:
    1. Get a local git clone of Drupal core 11.x.
    2. composer require drupal/config_inspector 
    3. composer require drush/drush
    4. Run drush config:inspect --filter-keys=search.page.user_search --detail --list-constraints

    Test Result:
    Search page config entity is fully validated after the changes.

    The below are before and after inspections of the search page configuration:

    Before:

    ---------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
      Key                                                  Status    Validatable   Data   Validation constraints                                                                       
     ---------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
      search.page.user_search                              Correct   80%           โœ…โ“   ValidKeys: '<infer>'                                                                         
       search.page.user_search:                            Correct   Validatable   โœ…โœ…   ValidKeys: '<infer>'                                                                         
       search.page.user_search:_core                       Correct   Validatable   โœ…โœ…   ValidKeys:                                                                                   
                                                                                            - default_config_hash                                                                      
       search.page.user_search:_core.default_config_hash   Correct   Validatable   โœ…โœ…   NotNull: {  }                                                                                
                                                                                          Regex: '/^[a-zA-Z0-9\-_]+$/'                                                                 
                                                                                          Length: 43                                                                                   
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
       search.page.user_search:configuration               Correct   NOT           โœ…โ“   โŒ @todo Add validation constraints to ancestor type: search.plugin.user_search              
       search.page.user_search:dependencies                Correct   Validatable   โœ…โœ…   ValidKeys: '<infer>'                                                                         
       search.page.user_search:dependencies.module         Correct   NOT           โœ…โ“   โŒ @todo Add validation constraints to ancestor type: config_dependencies                    
       search.page.user_search:dependencies.module.0       Correct   Validatable   โœ…โœ…   NotBlank: {  }                                                                               
                                                                                          ExtensionName: {  }                                                                          
                                                                                          ExtensionExists: module                                                                      
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
       search.page.user_search:id                          Correct   Validatable   โœ…โœ…   Regex:                                                                                       
                                                                                            pattern: '/^[a-z0-9_]+$/'                                                                  
                                                                                            message: 'The %value machine name is not valid.'                                           
                                                                                          Length:                                                                                      
                                                                                            max: 166                                                                                   
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
       search.page.user_search:label                       Correct   Validatable   โœ…โœ…   Regex:                                                                                       
                                                                                            pattern: '/([^\PC])/u'                                                                     
                                                                                            match: false                                                                               
                                                                                            message: 'Labels are not allowed to span multiple lines or contain control characters.'    
                                                                                          NotBlank: {  }                                                                               
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
       search.page.user_search:langcode                    Correct   Validatable   โœ…โœ…   NotNull: {  }                                                                                
                                                                                          Choice:                                                                                      
                                                                                            callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'  
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
       search.page.user_search:path                        Correct   NOT           โœ…โ“   โš ๏ธ  @todo Add validation constraints to config entity type: search.page.*                    
       search.page.user_search:plugin                      Correct   Validatable   โœ…โœ…   PluginExists:                                                                                
                                                                                            manager: plugin.manager.search                                                             
                                                                                            interface: Drupal\search\Plugin\SearchInterface                                            
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
       search.page.user_search:status                      Correct   Validatable   โœ…โœ…   โ†ฃ PrimitiveType: {  }                                                                        
       search.page.user_search:uuid                        Correct   Validatable   โœ…โœ…   Uuid: {  }                                                                                   
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
       search.page.user_search:weight                      Correct   Validatable   โœ…โœ…   Range:                                                                                       
                                                                                            min: -2147483648                                                                           
                                                                                            max: 2147483647                                                                            
                                                                                          FullyValidatable: null                                                                       
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
     ---------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 

    After:

    ---------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
      Key                                                  Status    Validatable   Data   Validation constraints                                                                       
     ---------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
      search.page.user_search                              Correct   100%          โœ…โœ…   ValidKeys: '<infer>'                                                                         
                                                                                          FullyValidatable: null                                                                       
       search.page.user_search:                            Correct   Validatable   โœ…โœ…   ValidKeys: '<infer>'                                                                         
                                                                                          FullyValidatable: null                                                                       
       search.page.user_search:_core                       Correct   Validatable   โœ…โœ…   ValidKeys:                                                                                   
                                                                                            - default_config_hash                                                                      
                                                                                          โ†ฃ NotNull: {  }                                                                              
       search.page.user_search:_core.default_config_hash   Correct   Validatable   โœ…โœ…   NotNull: {  }                                                                                
                                                                                          Regex: '/^[a-zA-Z0-9\-_]+$/'                                                                 
                                                                                          Length: 43                                                                                   
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
       search.page.user_search:configuration               Correct   Validatable   โœ…โœ…   โ†ฃ NotNull: {  }                                                                              
       search.page.user_search:dependencies                Correct   Validatable   โœ…โœ…   ValidKeys: '<infer>'                                                                         
                                                                                          โ†ฃ NotNull: {  }                                                                              
       search.page.user_search:dependencies.module         Correct   Validatable   โœ…โœ…   โ†ฃ NotNull: {  }                                                                              
       search.page.user_search:dependencies.module.0       Correct   Validatable   โœ…โœ…   NotBlank: {  }                                                                               
                                                                                          ExtensionName: {  }                                                                          
                                                                                          ExtensionExists: module                                                                      
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
                                                                                          โ†ฃ NotNull: {  }                                                                              
       search.page.user_search:id                          Correct   Validatable   โœ…โœ…   Regex:                                                                                       
                                                                                            pattern: '/^[a-z0-9_]+$/'                                                                  
                                                                                            message: 'The %value machine name is not valid.'                                           
                                                                                          Length:                                                                                      
                                                                                            max: 166                                                                                   
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
                                                                                          โ†ฃ NotNull: {  }                                                                              
       search.page.user_search:label                       Correct   Validatable   โœ…โœ…   Regex:                                                                                       
                                                                                            pattern: '/([^\PC])/u'                                                                     
                                                                                            match: false                                                                               
                                                                                            message: 'Labels are not allowed to span multiple lines or contain control characters.'    
                                                                                          NotBlank: {  }                                                                               
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
                                                                                          โ†ฃ NotNull: {  }                                                                              
       search.page.user_search:langcode                    Correct   Validatable   โœ…โœ…   NotNull: {  }                                                                                
                                                                                          Choice:                                                                                      
                                                                                            callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'  
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
       search.page.user_search:path                        Correct   Validatable   โœ…โœ…   NotBlank: {  }                                                                               
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
                                                                                          โ†ฃ NotNull: {  }                                                                              
       search.page.user_search:plugin                      Correct   Validatable   โœ…โœ…   PluginExists:                                                                                
                                                                                            manager: plugin.manager.search                                                             
                                                                                            interface: Drupal\search\Plugin\SearchInterface                                            
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
                                                                                          โ†ฃ NotNull: {  }                                                                              
       search.page.user_search:status                      Correct   Validatable   โœ…โœ…   โ†ฃ PrimitiveType: {  }                                                                        
                                                                                          โ†ฃ NotNull: {  }                                                                              
       search.page.user_search:uuid                        Correct   Validatable   โœ…โœ…   Uuid: {  }                                                                                   
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
                                                                                          โ†ฃ NotNull: {  }                                                                              
       search.page.user_search:weight                      Correct   Validatable   โœ…โœ…   Range:                                                                                       
                                                                                            min: -2147483648                                                                           
                                                                                            max: 2147483647                                                                            
                                                                                          FullyValidatable: null                                                                       
                                                                                          โ†ฃ PrimitiveType: {  }                                                                        
                                                                                          โ†ฃ NotNull: {  }                                                                              
     ---------------------------------------------------- --------- ------------- ------ ---------------------------------------------------------------------------------------------

    Thanks!

  • Status changed to RTBC 7 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium borisson_ Mechelen, ๐Ÿ‡ง๐Ÿ‡ช

    Changes look good to me. RTBC.

    • alexpott โ†’ committed 900d64b9 on 11.x
      Issue #3456133 by narendraR, VinmayiSwamy: Add validation constraints to...
  • Status changed to Fixed 7 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom alexpott ๐Ÿ‡ช๐Ÿ‡บ๐ŸŒ

    This looks great.

    Committed 900d64b and pushed to 11.x. Thanks!

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

Production build 0.71.5 2024