Add validation constraints to node.type.*

Created on 29 October 2023, about 1 year ago
Updated 31 October 2023, about 1 year ago

Problem/Motivation

Node types have 1 property paths that are not yet validatable:

./vendor/bin/drush config:inspect --filter-keys=node.type.page --detail --list-constraints --fields=key,validatability,constraints
➜  πŸ€– Analyzing…

 ------------------------------------------- ------------- --------------------------------------------------------------------------------------------- 
  Key                                         Validatable   Validation constraints                                                                       
 ------------------------------------------- ------------- --------------------------------------------------------------------------------------------- 
  node.type.page                              93%           ValidKeys: '<infer>'                                                                         
   node.type.page:                            Validatable   ValidKeys: '<infer>'                                                                         
   node.type.page:_core                       Validatable   ValidKeys:                                                                                   
                                                              - default_config_hash                                                                      
   node.type.page:_core.default_config_hash   Validatable   NotNull: {  }                                                                                
                                                            Regex: '/^[a-zA-Z0-9\-_]+$/'                                                                 
                                                            Length: 43                                                                                   
                                                            ↣ PrimitiveType: {  }                                                                        
   node.type.page:dependencies                Validatable   ValidKeys: '<infer>'                                                                         
   node.type.page:description                 Validatable   Regex:                                                                                       
                                                              pattern: '/([^\PC\x09\x0a\x0d])/u'                                                         
                                                              match: false                                                                               
                                                              message: 'Text is not allowed to contain control characters, only visible characters.'     
                                                            ↣ PrimitiveType: {  }                                                                        
   node.type.page:display_submitted           Validatable   ↣ PrimitiveType: {  }                                                                        
   node.type.page:help                        Validatable   Regex:                                                                                       
                                                              pattern: '/([^\PC\x09\x0a\x0d])/u'                                                         
                                                              match: false                                                                               
                                                              message: 'Text is not allowed to contain control characters, only visible characters.'     
                                                            ↣ PrimitiveType: {  }                                                                        
   node.type.page:langcode                    Validatable   NotNull: {  }                                                                                
                                                            Choice:                                                                                      
                                                              callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'  
                                                            ↣ PrimitiveType: {  }                                                                        
   node.type.page:name                        Validatable   Regex:                                                                                       
                                                              pattern: '/([^\PC])/u'                                                                     
                                                              match: false                                                                               
                                                              message: 'Labels are not allowed to span multiple lines or contain control characters.'    
                                                            NotBlank: {  }                                                                               
                                                            ↣ PrimitiveType: {  }                                                                        
   node.type.page:new_revision                Validatable   ↣ PrimitiveType: {  }                                                                        
   node.type.page:preview_mode                NOT           ⚠️  @todo Add validation constraints to config entity type: node.type.*                      
   node.type.page:status                      Validatable   ↣ PrimitiveType: {  }                                                                        
   node.type.page:type                        Validatable   Length:                                                                                      
                                                              max: 32                                                                                    
                                                            ↣ PrimitiveType: {  }                                                                        
                                                            ↣ Regex:                                                                                     
                                                              pattern: '/^[a-z0-9_]+$/'                                                                  
                                                              message: 'The %value machine name is not valid.'                                           
   node.type.page:uuid                        Validatable   Uuid: {  }                                                                                   
                                                            ↣ 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=node.type.page --detail --list-constraints

Proposed resolution

Add validation constraints to:

  1. node.type.*:preview_mode

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

  1. node.type.*:preview_mode

User interface changes

None.

API changes

None.

Data model changes

More validation πŸš€

Release notes snippet

None.

πŸ“Œ Task
Status

Closed: duplicate

Version

11.0 πŸ”₯

Component
Node systemΒ  β†’

Last updated 4 days ago

No maintainer
Created by

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

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

Comments & Activities

Production build 0.71.5 2024