Identify which properties must be made validatable elsewhere

Created on 3 October 2023, over 1 year ago
Updated 4 October 2023, over 1 year ago

Problem/Motivation

As a developer, I want the output of

$ vendor/bin/drush config:inspect --detail --list-constraints

to tell me where validation must be added: on the actual type, or the inherited type.

Steps to reproduce

Today (if I remove the constraints on _core_config_info.default_config_hash):

$ vendor/bin/drush config:inspect --filter-keys=automated_cron.settings --detail --list-constraints
 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ---------------------------------------------------- --------- ------------- ------ ------------------------- 
  Key                                                  Status    Validatable   Data   Validation constraints   
 ---------------------------------------------------- --------- ------------- ------ ------------------------- 
  automated_cron.settings                              Correct   50%           ✅❓   ValidKeys: '<infer>'     
   automated_cron.settings:                            Correct   Validatable   ✅✅   ValidKeys: '<infer>'     
   automated_cron.settings:_core                       Correct   Validatable   ✅✅   ValidKeys:               
                                                                                        - default_config_hash  
   automated_cron.settings:_core.default_config_hash   Correct   NOT           ✅❓                            
   automated_cron.settings:interval                    Correct   NOT           ✅❓                            
 ---------------------------------------------------- --------- ------------- ------ ------------------------- 

and

$ vendor/bin/drush config:inspect --filter-keys=block.block.olivero_syndicate --detail --list-constraints
 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ---------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
  Key                                                        Status    Validatable   Data   Validation constraints                                                                       
 ---------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
  block.block.olivero_syndicate                              Correct   50%           ✅❓   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:                            Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:_core                       Correct   Validatable   ✅✅   ValidKeys:                                                                                   
                                                                                              - default_config_hash                                                                      
   block.block.olivero_syndicate:_core.default_config_hash   Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:dependencies                Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:dependencies.module         Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:dependencies.module.0       Correct   Validatable   ✅✅   NotBlank: {  }                                                                               
                                                                                            ExtensionName: {  }                                                                          
                                                                                            ExtensionExists: module                                                                      
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:dependencies.theme          Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:dependencies.theme.0        Correct   Validatable   ✅✅   NotBlank: {  }                                                                               
                                                                                            ExtensionName: {  }                                                                          
                                                                                            ExtensionExists: theme                                                                       
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:id                          Correct   Validatable   ✅✅   Regex:                                                                                       
                                                                                              pattern: '/^[a-z0-9_.]+$/'                                                                 
                                                                                              message: 'The %value machine name is not valid.'                                           
                                                                                            ↣ PrimitiveType: {  }                                                                        
                                                                                            ↣ Length:                                                                                    
                                                                                              max: 166                                                                                   
   block.block.olivero_syndicate:langcode                    Correct   Validatable   ✅✅   NotNull: {  }                                                                                
                                                                                            Choice:                                                                                      
                                                                                              callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'  
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:plugin                      Correct   Validatable   ✅✅   PluginExists:                                                                                
                                                                                              manager: plugin.manager.block                                                              
                                                                                              interface: Drupal\Core\Block\BlockPluginInterface                                          
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:provider                    Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:region                      Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:settings                    Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:settings.block_count        Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:settings.id                 Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:settings.label              Correct   Validatable   ✅✅   Regex:                                                                                       
                                                                                              pattern: '/([^\PC])/u'                                                                     
                                                                                              match: false                                                                               
                                                                                              message: 'Labels are not allowed to span multiple lines or contain control characters.'    
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:settings.label_display      Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:settings.provider           Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:status                      Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:theme                       Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:uuid                        Correct   Validatable   ✅✅   Uuid: {  }                                                                                   
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:visibility                  Correct   NOT           ✅❓                                                                                                
   block.block.olivero_syndicate:weight                      Correct   NOT           ✅❓                                                                                                
 ---------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 

Proposed resolution

Desired:

$ vendor/bin/drush config:inspect --filter-keys=automated_cron.settings --detail --list-constraints
 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ---------------------------------------------------- --------- ------------- ------ ------------------------------------------------------------------------- 
  Key                                                  Status    Validatable   Data   Validation constraints                                                   
 ---------------------------------------------------- --------- ------------- ------ ------------------------------------------------------------------------- 
  automated_cron.settings                              Correct   50%           ✅❓   ValidKeys: '<infer>'                                                     
   automated_cron.settings:                            Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                     
   automated_cron.settings:_core                       Correct   Validatable   ✅✅   ValidKeys:                                                               
                                                                                        - default_config_hash                                                  
   automated_cron.settings:_core.default_config_hash   Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: _core_config_info  
   automated_cron.settings:interval                    Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints here                                
 ---------------------------------------------------- --------- ------------- ------ ------------------------------------------------------------------------- 

and

$ vendor/bin/drush config:inspect --filter-keys=block.block.olivero_syndicate --detail --list-constraints
 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ---------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
  Key                                                        Status    Validatable   Data   Validation constraints                                                                       
 ---------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
  block.block.olivero_syndicate                              Correct   50%           ✅❓   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:                            Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:_core                       Correct   Validatable   ✅✅   ValidKeys:                                                                                   
                                                                                              - default_config_hash                                                                      
   block.block.olivero_syndicate:_core.default_config_hash   Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: _core_config_info                      
   block.block.olivero_syndicate:dependencies                Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:dependencies.module         Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: config_dependencies                    
   block.block.olivero_syndicate:dependencies.module.0       Correct   Validatable   ✅✅   NotBlank: {  }                                                                               
                                                                                            ExtensionName: {  }                                                                          
                                                                                            ExtensionExists: module                                                                      
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:dependencies.theme          Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: config_dependencies                    
   block.block.olivero_syndicate:dependencies.theme.0        Correct   Validatable   ✅✅   NotBlank: {  }                                                                               
                                                                                            ExtensionName: {  }                                                                          
                                                                                            ExtensionExists: theme                                                                       
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:id                          Correct   Validatable   ✅✅   Regex:                                                                                       
                                                                                              pattern: '/^[a-z0-9_.]+$/'                                                                 
                                                                                              message: 'The %value machine name is not valid.'                                           
                                                                                            ↣ PrimitiveType: {  }                                                                        
                                                                                            ↣ Length:                                                                                    
                                                                                              max: 166                                                                                   
   block.block.olivero_syndicate:langcode                    Correct   Validatable   ✅✅   NotNull: {  }                                                                                
                                                                                            Choice:                                                                                      
                                                                                              callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'  
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:plugin                      Correct   Validatable   ✅✅   PluginExists:                                                                                
                                                                                              manager: plugin.manager.block                                                              
                                                                                              interface: Drupal\Core\Block\BlockPluginInterface                                          
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:provider                    Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints to config entity type: block.block.*                    
   block.block.olivero_syndicate:region                      Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints to config entity type: block.block.*                    
   block.block.olivero_syndicate:settings                    Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                                         
   block.block.olivero_syndicate:settings.block_count        Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: block.settings.node_syndicate_block    
   block.block.olivero_syndicate:settings.id                 Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: block.settings.node_syndicate_block    
   block.block.olivero_syndicate:settings.label              Correct   Validatable   ✅✅   Regex:                                                                                       
                                                                                              pattern: '/([^\PC])/u'                                                                     
                                                                                              match: false                                                                               
                                                                                              message: 'Labels are not allowed to span multiple lines or contain control characters.'    
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:settings.label_display      Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: block.settings.node_syndicate_block    
   block.block.olivero_syndicate:settings.provider           Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: block.settings.node_syndicate_block    
   block.block.olivero_syndicate:status                      Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:theme                       Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints to config entity type: block.block.*                    
   block.block.olivero_syndicate:uuid                        Correct   Validatable   ✅✅   Uuid: {  }                                                                                   
                                                                                            ↣ PrimitiveType: {  }                                                                        
   block.block.olivero_syndicate:visibility                  Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints to config entity type: block.block.*                    
   block.block.olivero_syndicate:weight                      Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints to config entity type: block.block.*                    
 ---------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 

Note how _core.default_config_hash is simple (just one data/config schema type level up), but dependencies.module is not: the parent type is sequence, but adding constraints there does not make sense. They should be added one level higher, in config_dependencies.

A more extreme example of this can be found in core.entity_form_display.node.article.default, where we need to up multiple levels.

Remaining tasks

None.

User interface changes

At /admin/reports/config-inspector/core.entity_form_display.node.article.default/tree:

API changes

N/A

Data model changes

N/A

Feature request
Status

Fixed

Version

2.1

Component

User interface

Created by

🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

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

Comments & Activities

Production build 0.71.5 2024