Add validation constraints to image.style.*

Created on 15 May 2024, 8 months ago
Updated 11 June 2024, 7 months ago

Problem/Motivation

Image style configuration entity is not yet fully validatable:

vendor/bin/drush config:inspect --filter-keys=image.style.large --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                                                                       
 -------------------------------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
  image.style.large                                                                Correct   83%           โœ…โ“   ValidKeys: '<infer>'                                                                         
   image.style.large:                                                              Correct   Validatable   โœ…โœ…   ValidKeys: '<infer>'                                                                         
   image.style.large:_core                                                         Correct   Validatable   โœ…โœ…   ValidKeys:                                                                                   
                                                                                                                    - default_config_hash                                                                      
   image.style.large:_core.default_config_hash                                     Correct   Validatable   โœ…โœ…   NotNull: {  }                                                                                
                                                                                                                  Regex: '/^[a-zA-Z0-9\-_]+$/'                                                                 
                                                                                                                  Length: 43                                                                                   
                                                                                                                  โ†ฃ PrimitiveType: {  }                                                                        
   image.style.large:dependencies                                                  Correct   Validatable   โœ…โœ…   ValidKeys: '<infer>'                                                                         
   image.style.large:effects                                                       Correct   NOT           โœ…โ“   โš ๏ธ  @todo Add validation constraints to config entity type: image.style.*                    
   image.style.large:effects.6e8fe467-84c1-4ef0-a73b-7eccf1cc20e8                  Correct   Validatable   โœ…โœ…   ValidKeys: '<infer>'                                                                         
   image.style.large:effects.6e8fe467-84c1-4ef0-a73b-7eccf1cc20e8.data             Correct   Validatable   โœ…โœ…   ValidKeys: '<infer>'                                                                         
   image.style.large:effects.6e8fe467-84c1-4ef0-a73b-7eccf1cc20e8.data.extension   Correct   NOT           โœ…โ“   โŒ @todo Add validation constraints to ancestor type: image.effect.image_convert             
   image.style.large:effects.6e8fe467-84c1-4ef0-a73b-7eccf1cc20e8.id               Correct   Validatable   โœ…โœ…   PluginExists:                                                                                
                                                                                                                    manager: plugin.manager.image.effect                                                       
                                                                                                                    interface: Drupal\image\ImageEffectInterface                                               
                                                                                                                  โ†ฃ PrimitiveType: {  }                                                                        
   image.style.large:effects.6e8fe467-84c1-4ef0-a73b-7eccf1cc20e8.uuid             Correct   Validatable   โœ…โœ…   Uuid: {  }                                                                                   
                                                                                                                  โ†ฃ PrimitiveType: {  }                                                                        
   image.style.large:effects.6e8fe467-84c1-4ef0-a73b-7eccf1cc20e8.weight           Correct   Validatable   โœ…โœ…   Range:                                                                                       
                                                                                                                    min: -2147483648                                                                           
                                                                                                                    max: 2147483647                                                                            
                                                                                                                  FullyValidatable: null                                                                       
                                                                                                                  โ†ฃ PrimitiveType: {  }                                                                        
   image.style.large:effects.ddd73aa7-4bd6-4c85-b600-bdf2b1628d1d                  Correct   Validatable   โœ…โœ…   ValidKeys: '<infer>'                                                                         
   image.style.large:effects.ddd73aa7-4bd6-4c85-b600-bdf2b1628d1d.data             Correct   Validatable   โœ…โœ…   ValidKeys: '<infer>'                                                                         
   image.style.large:effects.ddd73aa7-4bd6-4c85-b600-bdf2b1628d1d.data.height      Correct   NOT           โœ…โ“   โŒ @todo Add validation constraints to ancestor type: image.effect.image_scale               
   image.style.large:effects.ddd73aa7-4bd6-4c85-b600-bdf2b1628d1d.data.upscale     Correct   Validatable   โœ…โœ…   โ†ฃ PrimitiveType: {  }                                                                        
   image.style.large:effects.ddd73aa7-4bd6-4c85-b600-bdf2b1628d1d.data.width       Correct   NOT           โœ…โ“   โŒ @todo Add validation constraints to ancestor type: image.effect.image_scale               
   image.style.large:effects.ddd73aa7-4bd6-4c85-b600-bdf2b1628d1d.id               Correct   Validatable   โœ…โœ…   PluginExists:                                                                                
                                                                                                                    manager: plugin.manager.image.effect                                                       
                                                                                                                    interface: Drupal\image\ImageEffectInterface                                               
                                                                                                                  โ†ฃ PrimitiveType: {  }                                                                        
   image.style.large:effects.ddd73aa7-4bd6-4c85-b600-bdf2b1628d1d.uuid             Correct   Validatable   โœ…โœ…   Uuid: {  }                                                                                   
                                                                                                                  โ†ฃ PrimitiveType: {  }                                                                        
   image.style.large:effects.ddd73aa7-4bd6-4c85-b600-bdf2b1628d1d.weight           Correct   Validatable   โœ…โœ…   Range:                                                                                       
                                                                                                                    min: -2147483648                                                                           
                                                                                                                    max: 2147483647                                                                            
                                                                                                                  FullyValidatable: null                                                                       
                                                                                                                  โ†ฃ PrimitiveType: {  }                                                                        
   image.style.large:label                                                         Correct   Validatable   โœ…โœ…   Regex:                                                                                       
                                                                                                                    pattern: '/([^\PC])/u'                                                                     
                                                                                                                    match: false                                                                               
                                                                                                                    message: 'Labels are not allowed to span multiple lines or contain control characters.'    
                                                                                                                  NotBlank: {  }                                                                               
                                                                                                                  โ†ฃ PrimitiveType: {  }                                                                        
   image.style.large:langcode                                                      Correct   Validatable   โœ…โœ…   NotNull: {  }                                                                                
                                                                                                                  Choice:                                                                                      
                                                                                                                    callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'  
                                                                                                                  โ†ฃ PrimitiveType: {  }                                                                        
   image.style.large:name                                                          Correct   Validatable   โœ…โœ…   Regex:                                                                                       
                                                                                                                    pattern: '/^[a-z0-9_]+$/'                                                                  
                                                                                                                    message: 'The %value machine name is not valid.'                                           
                                                                                                                  Length:                                                                                      
                                                                                                                    max: 166                                                                                   
                                                                                                                  โ†ฃ PrimitiveType: {  }                                                                        
   image.style.large:status                                                        Correct   Validatable   โœ…โœ…   โ†ฃ PrimitiveType: {  }                                                                        
   image.style.large:uuid                                                          Correct   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=image.style.large --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 #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
Image moduleย  โ†’

Last updated 3 days ago

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

Production build 0.71.5 2024