Improve display of validation constraints: constraint IDs instead of FQCNs and local vs inherited

Created on 2 June 2023, over 1 year ago
Updated 7 June 2023, over 1 year ago

Problem/Motivation

Quoting myself from #3216089-27: Expose validation constraints (and validatability %) in Config Inspector UI β†’ and #3216089-28: Expose validation constraints (and validatability %) in Config Inspector UI β†’ :

An idea for a follow-up could be to distinguish between inherited constraints vs local constraints β€” that would make it clear that for example the _core key (which is present in both cdn.settings and media.settings's Drush output) actually is of the type _core_config_info β€” so adding a validation constraint there would fix it everywhere.

+

Another follow-up would be to map the FQCNs to the equivalent types:

  • \Drupal\Core\Validation\Plugin\Validation\Constraint\PrimitiveTypeConstraint would become PrimitiveType because of
     * @Constraint(
     *   id = "PrimitiveType",
     *   label = @Translation("Primitive type", context = "Validation")
     * )
    
  • \Drupal\cdn\Plugin\Validation\Constraint\CdnDomainConstraint would become CdnDomain because of
     * @Constraint(
     *   id = "CdnDomain",
     *   label = @Translation("CDN domain", context = "Validation"),
     * )
    
  • and so on
  • … but that's really just a nice-to-have compared to today, where this information is still painfully difficult to access.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

N/A

Data model changes

N/A

πŸ“Œ Task
Status

Fixed

Version

2.1

Component

User interface

Created by

πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

Sign in to follow issues

Comments & Activities

  • Issue created by @wim leers
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    3 pass
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • πŸ‡­πŸ‡ΊHungary GΓ‘bor Hojtsy Hungary

    Looks like a great improvement indeed!

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    3 pass
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    For something more interesting, see $ vendor/bin/drush config:inspect --filter-keys=editor.editor.basic_html --detail --list-constraints's output after a fresh install (which made me refine the output for Drush because it was impossible to distinguish some things):

    $ vendor/bin/drush config:inspect --filter-keys=editor.editor.basic_html --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                                                           
     --------------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------- 
      editor.editor.basic_html                                        Correct   68%           βœ…β“                                                                                    
       editor.editor.basic_html:                                      Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:_core                                 Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:_core.default_config_hash             Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:dependencies                          Correct   Validatable   βœ…βœ…   ValidKeys: '<infer>'                                                             
       editor.editor.basic_html:dependencies.config                   Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:dependencies.config.0                 Correct   Validatable   βœ…βœ…   NotBlank: {  }                                                                   
                                                                                                     ConfigExists: {  }                                                               
                                                                                                     ↣ PrimitiveType: {  }                                                            
       editor.editor.basic_html:dependencies.module                   Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:dependencies.module.0                 Correct   Validatable   βœ…βœ…   NotBlank: {  }                                                                   
                                                                                                     ExtensionName: {  }                                                              
                                                                                                     ExtensionExists: module                                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
       editor.editor.basic_html:editor                                Correct   Validatable   βœ…βœ…   PluginExists:                                                                    
                                                                                                       manager: plugin.manager.editor                                                 
                                                                                                       interface: Drupal\editor\Plugin\EditorPluginInterface                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
       editor.editor.basic_html:format                                Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:image_upload                          Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:image_upload.directory                Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:image_upload.max_dimensions           Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:image_upload.max_dimensions.height    Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:image_upload.max_dimensions.width     Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:image_upload.max_size                 Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:image_upload.scheme                   Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:image_upload.status                   Correct   Validatable   βœ…βœ…   ↣ PrimitiveType: {  }                                                            
       editor.editor.basic_html:langcode                              Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:settings                              Correct   Validatable   βœ…βœ…   CKEditor5EnabledConfigurablePlugins: {  }                                        
       editor.editor.basic_html:settings.plugins                      Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:settings.plugins.ckeditor5_heading    Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:settings.plugins.ckeditor5_heading.   Correct   Validatable   βœ…βœ…   NotBlank:                                                                        
      enabled_headings                                                                                 message: 'Enable at least one heading, otherwise disable the Heading plugin.'  
       editor.editor.basic_html:settings.plugins.ckeditor5_heading.   Correct   Validatable   βœ…βœ…   Choice:                                                                          
      enabled_headings.0                                                                               callback: '\Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading::validChoices'     
                                                                                                     ↣ PrimitiveType: {  }                                                            
       editor.editor.basic_html:settings.plugins.ckeditor5_heading.   Correct   Validatable   βœ…βœ…   Choice:                                                                          
      enabled_headings.1                                                                               callback: '\Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading::validChoices'     
                                                                                                     ↣ PrimitiveType: {  }                                                            
       editor.editor.basic_html:settings.plugins.ckeditor5_heading.   Correct   Validatable   βœ…βœ…   Choice:                                                                          
      enabled_headings.2                                                                               callback: '\Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading::validChoices'     
                                                                                                     ↣ PrimitiveType: {  }                                                            
       editor.editor.basic_html:settings.plugins.ckeditor5_heading.   Correct   Validatable   βœ…βœ…   Choice:                                                                          
      enabled_headings.3                                                                               callback: '\Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading::validChoices'     
                                                                                                     ↣ PrimitiveType: {  }                                                            
       editor.editor.basic_html:settings.plugins.ckeditor5_heading.   Correct   Validatable   βœ…βœ…   Choice:                                                                          
      enabled_headings.4                                                                               callback: '\Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading::validChoices'     
                                                                                                     ↣ PrimitiveType: {  }                                                            
       editor.editor.basic_html:settings.plugins.ckeditor5_heading.   Correct   Validatable   βœ…βœ…   Choice:                                                                          
      enabled_headings.5                                                                               callback: '\Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading::validChoices'     
                                                                                                     ↣ PrimitiveType: {  }                                                            
       editor.editor.basic_html:settings.plugins.ckeditor5_list       Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:settings.plugins.ckeditor5_list.rev   Correct   Validatable   βœ…βœ…   NotNull: {  }                                                                    
      ersed                                                                                          ↣ PrimitiveType: {  }                                                            
       editor.editor.basic_html:settings.plugins.ckeditor5_list.sta   Correct   Validatable   βœ…βœ…   NotNull: {  }                                                                    
      rtIndex                                                                                        ↣ PrimitiveType: {  }                                                            
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   NOT           βœ…β“                                                                                    
      iting                                                                                                                                                                           
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   NOT           βœ…β“                                                                                    
      iting.allowed_tags                                                                                                                                                              
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   Validatable   βœ…βœ…   SourceEditingRedundantTags: {  }                                                 
      iting.allowed_tags.0                                                                           SourceEditingPreventSelfXssConstraint: {  }                                      
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5Element: {  }                                                         
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   Validatable   βœ…βœ…   SourceEditingRedundantTags: {  }                                                 
      iting.allowed_tags.1                                                                           SourceEditingPreventSelfXssConstraint: {  }                                      
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5Element: {  }                                                         
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   Validatable   βœ…βœ…   SourceEditingRedundantTags: {  }                                                 
      iting.allowed_tags.10                                                                          SourceEditingPreventSelfXssConstraint: {  }                                      
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5Element: {  }                                                         
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   Validatable   βœ…βœ…   SourceEditingRedundantTags: {  }                                                 
      iting.allowed_tags.11                                                                          SourceEditingPreventSelfXssConstraint: {  }                                      
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5Element: {  }                                                         
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   Validatable   βœ…βœ…   SourceEditingRedundantTags: {  }                                                 
      iting.allowed_tags.12                                                                          SourceEditingPreventSelfXssConstraint: {  }                                      
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5Element: {  }                                                         
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   Validatable   βœ…βœ…   SourceEditingRedundantTags: {  }                                                 
      iting.allowed_tags.2                                                                           SourceEditingPreventSelfXssConstraint: {  }                                      
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5Element: {  }                                                         
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   Validatable   βœ…βœ…   SourceEditingRedundantTags: {  }                                                 
      iting.allowed_tags.3                                                                           SourceEditingPreventSelfXssConstraint: {  }                                      
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5Element: {  }                                                         
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   Validatable   βœ…βœ…   SourceEditingRedundantTags: {  }                                                 
      iting.allowed_tags.4                                                                           SourceEditingPreventSelfXssConstraint: {  }                                      
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5Element: {  }                                                         
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   Validatable   βœ…βœ…   SourceEditingRedundantTags: {  }                                                 
      iting.allowed_tags.5                                                                           SourceEditingPreventSelfXssConstraint: {  }                                      
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5Element: {  }                                                         
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   Validatable   βœ…βœ…   SourceEditingRedundantTags: {  }                                                 
      iting.allowed_tags.6                                                                           SourceEditingPreventSelfXssConstraint: {  }                                      
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5Element: {  }                                                         
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   Validatable   βœ…βœ…   SourceEditingRedundantTags: {  }                                                 
      iting.allowed_tags.7                                                                           SourceEditingPreventSelfXssConstraint: {  }                                      
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5Element: {  }                                                         
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   Validatable   βœ…βœ…   SourceEditingRedundantTags: {  }                                                 
      iting.allowed_tags.8                                                                           SourceEditingPreventSelfXssConstraint: {  }                                      
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5Element: {  }                                                         
       editor.editor.basic_html:settings.plugins.ckeditor5_sourceEd   Correct   Validatable   βœ…βœ…   SourceEditingRedundantTags: {  }                                                 
      iting.allowed_tags.9                                                                           SourceEditingPreventSelfXssConstraint: {  }                                      
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5Element: {  }                                                         
       editor.editor.basic_html:settings.plugins.media_media          Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:settings.plugins.media_media.allow_   Correct   Validatable   βœ…βœ…   NotNull: {  }                                                                    
      view_mode_override                                                                             ↣ PrimitiveType: {  }                                                            
       editor.editor.basic_html:settings.toolbar                      Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:settings.toolbar.items                Correct   NOT           βœ…β“                                                                                    
       editor.editor.basic_html:settings.toolbar.items.0              Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:settings.toolbar.items.1              Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:settings.toolbar.items.10             Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:settings.toolbar.items.11             Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:settings.toolbar.items.12             Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:settings.toolbar.items.13             Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:settings.toolbar.items.14             Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:settings.toolbar.items.2              Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:settings.toolbar.items.3              Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:settings.toolbar.items.4              Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:settings.toolbar.items.5              Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:settings.toolbar.items.6              Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:settings.toolbar.items.7              Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:settings.toolbar.items.8              Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:settings.toolbar.items.9              Correct   Validatable   βœ…βœ…   CKEditor5ToolbarItemConditionsMet: {  }                                          
                                                                                                     ↣ PrimitiveType: {  }                                                            
                                                                                                     ↣ CKEditor5ToolbarItem: {  }                                                     
       editor.editor.basic_html:status                                Correct   Validatable   βœ…βœ…   ↣ PrimitiveType: {  }                                                            
       editor.editor.basic_html:uuid                                  Correct   Validatable   βœ…βœ…   Uuid: {  }                                                                       
                                                                                                     ↣ PrimitiveType: {  }                                                            
     --------------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------- 
    
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Here's a plain text file with the output I quoted in #4 β€” d.o's formatting makes it unusable 🫣

  • Status changed to Needs work over 1 year ago
  • πŸ‡³πŸ‡±Netherlands ronaldtebrake

    That drush output, how neat 😍

    ---

       private static function getPrintableConstraints(ConfigSchemaValidatability $validatability, string $property_path): array {
    +    $all_constraints = $validatability->getConstraints($property_path);
    +    $local_constraints = array_map(
    +      fn (string $constraint_name, $constraints_options) => trim(Yaml::encode([$constraint_name => $constraints_options])),
    +      array_keys($all_constraints['local']),
    +      array_values($all_constraints['local'])
    +    );
    +    $inherited_constraints = array_map(
    +      fn (string $constraint_name, $constraints_options) => "Ò†£ " . trim(Yaml::encode([$constraint_name => $constraints_options])),
    +      array_keys($all_constraints['inherited']),
    +      array_values($all_constraints['inherited'])
    +    );
    +
    +    return array_merge($local_constraints, $inherited_constraints);
         return array_map(
           fn (Constraint $constraint) => get_class($constraint),
           $validatability->getConstraints($property_path)
    

    Think we can remove the return array_map at the end.

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    3 pass
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Thanks! 🫣 Dead code indeed :P

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    @GΓ‘bor Hojtsy gave me commit access at DrupalCon! πŸ€“πŸ˜„

    Let's ship this!

  • Status changed to RTBC over 1 year ago
  • Status changed to Fixed over 1 year ago
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024