Allow vocabularies to be validated via the API, not just during form submissions

Created on 23 May 2013, about 11 years ago
Updated 13 March 2024, 3 months ago

Problem/Motivation

Vocabulary config entities are mostly validatable using the typed config system, but not quite. There is one property (weight) that are not yet validatable:

$ ./vendor/bin/drush config:inspect --filter-keys=taxonomy.vocabulary.tags --detail --list-constraints  --fields=key,validatability,constraints
➜  πŸ€– Analyzing…

 -------------------- ------------- ----------------------------------------------------------------- 
  Key                  Validatable   Validation constraints                                           
 -------------------- ------------- ----------------------------------------------------------------- 
  taxonomy.vocabular   92%           ValidKeys: '<infer>'                                             
  y.tags                                                                                              
   taxonomy.vocabula   Validatable   ValidKeys: '<infer>'                                             
  ry.tags:                                                                                            
   taxonomy.vocabula   Validatable   ValidKeys:                                                       
  ry.tags:_core                        - default_config_hash                                          
   taxonomy.vocabula   Validatable   NotNull: {  }                                                    
  ry.tags:_core.defa                 Regex: '/^[a-zA-Z0-9\-_]+$/'                                     
  ult_config_hash                    Length: 43                                                       
                                     ↣ PrimitiveType: {  }                                            
   taxonomy.vocabula   Validatable   ValidKeys: '<infer>'                                             
  ry.tags:dependenci                                                                                  
  es                                                                                                  
   taxonomy.vocabula   Validatable   Regex:                                                           
  ry.tags:descriptio                   pattern: '/([^\PC])/u'                                         
  n                                    match: false                                                   
                                       message: 'Labels are not allowed to span multiple lines or     
                                     contain control characters.'                                     
                                     ↣ PrimitiveType: {  }                                            
   taxonomy.vocabula   Validatable   NotNull: {  }                                                    
  ry.tags:langcode                   Choice:                                                          
                                       callback:                                                      
                                     'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAl  
                                     lValidLangcodes'                                                 
                                     ↣ PrimitiveType: {  }                                            
   taxonomy.vocabula   Validatable   Regex:                                                           
  ry.tags:name                         pattern: '/([^\PC])/u'                                         
                                       match: false                                                   
                                       message: 'Labels are not allowed to span multiple lines or     
                                     contain control characters.'                                     
                                     NotBlank: {  }                                                   
                                     ↣ PrimitiveType: {  }                                            
   taxonomy.vocabula   Validatable   ↣ PrimitiveType: {  }                                            
  ry.tags:new_revisi                                                                                  
  on                                                                                                  
   taxonomy.vocabula   Validatable   ↣ PrimitiveType: {  }                                            
  ry.tags:status                                                                                      
   taxonomy.vocabula   Validatable   Uuid: {  }                                                       
  ry.tags:uuid                       ↣ PrimitiveType: {  }                                            
   taxonomy.vocabula   Validatable   Length:                                                          
  ry.tags:vid                          max: 32                                                        
                                     ↣ PrimitiveType: {  }                                            
                                     ↣ Regex:                                                         
                                       pattern: '/^[a-z0-9_]+$/'                                      
                                       message: 'The %value machine name is not valid.'               
   taxonomy.vocabula   NOT           ⚠️  @todo Add validation constraints to config entity type:      
  ry.tags:weight                     taxonomy.vocabulary.*                                            
 -------------------- ------------- ----------------------------------------------------------------- 

Remarks:

  1. There is a plan to deprecate weight, but that's an independent concern: πŸ“Œ Deprecate vocabulary weight property Needs work
  2. The type for description is wrong in two ways: A) it currently is label and should be text, because multiple lines are allowed, B) the description is optional, just like it is for NodeType for example (see πŸ“Œ [PP-1] Make NodeType config entities fully validatable Needs review and its change record β†’ ), so it should be marked nullable: true and needs an update path to convert an empty string to NULL

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=announcements_feed--detail --list-constraints

Proposed resolution

  1. Add validation constraints.
  2. Mark FullyValidatable.
  3. Write update path + update path test

Remaining tasks

Review.

User interface changes

None.

API changes

description is no longer allowed to be the empty string ('') β€” vocabularies without a description must use null. Change record: https://www.drupal.org/node/3421927 β†’

Data model changes

None.

Release notes snippet

N/A

πŸ“Œ Task
Status

Fixed

Version

10.3 ✨

Component
TaxonomyΒ  β†’

Last updated 1 day ago

  • Maintained by
  • πŸ‡ΊπŸ‡ΈUnited States @xjm
  • πŸ‡¬πŸ‡§United Kingdom @catch
Created by

πŸ‡¦πŸ‡ΉAustria fago Vienna

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024