Add validation constraints to system.action.*

Created on 23 May 2024, 7 months ago
Updated 17 July 2024, 5 months ago

Problem/Motivation

Action entity is not yet validatable:

vendor/bin/drush config:inspect --filter-keys=system.action.user_cancel_user_action --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                                                                              
 ------------------------------------------------------------------ --------- ------------- ------ ---------------------------------------------------------------------------------------------------- 
  system.action.user_cancel_user_action                              Correct   79%           โœ…โ“   ValidKeys: '<infer>'                                                                                
   system.action.user_cancel_user_action:                            Correct   Validatable   โœ…โœ…   ValidKeys: '<infer>'                                                                                
   system.action.user_cancel_user_action:_core                       Correct   Validatable   โœ…โœ…   ValidKeys:                                                                                          
                                                                                                      - default_config_hash                                                                             
   system.action.user_cancel_user_action:_core.default_config_hash   Correct   Validatable   โœ…โœ…   NotNull: {  }                                                                                       
                                                                                                    Regex: '/^[a-zA-Z0-9\-_]+$/'                                                                        
                                                                                                    Length: 43                                                                                          
                                                                                                    โ†ฃ PrimitiveType: {  }                                                                               
   system.action.user_cancel_user_action:configuration               Correct   NOT           โœ…โ“   โŒ @todo Add validation constraints to ancestor type: action.configuration.user_cancel_user_action  
   system.action.user_cancel_user_action:dependencies                Correct   Validatable   โœ…โœ…   ValidKeys: '<infer>'                                                                                
   system.action.user_cancel_user_action:dependencies.module         Correct   NOT           โœ…โ“   โŒ @todo Add validation constraints to ancestor type: config_dependencies                           
   system.action.user_cancel_user_action:dependencies.module.0       Correct   Validatable   โœ…โœ…   NotBlank: {  }                                                                                      
                                                                                                    ExtensionName: {  }                                                                                 
                                                                                                    ExtensionExists: module                                                                             
                                                                                                    โ†ฃ PrimitiveType: {  }                                                                               
   system.action.user_cancel_user_action:id                          Correct   Validatable   โœ…โœ…   Regex:                                                                                              
                                                                                                      pattern: '/^[a-z0-9_\.]+$/'                                                                       
                                                                                                      message: 'The %value machine name is not valid.'                                                  
                                                                                                    โ†ฃ PrimitiveType: {  }                                                                               
                                                                                                    โ†ฃ Length:                                                                                           
                                                                                                      max: 166                                                                                          
   system.action.user_cancel_user_action:label                       Correct   Validatable   โœ…โœ…   Regex:                                                                                              
                                                                                                      pattern: '/([^\PC])/u'                                                                            
                                                                                                      match: false                                                                                      
                                                                                                      message: 'Labels are not allowed to span multiple lines or contain control characters.'           
                                                                                                    NotBlank: {  }                                                                                      
                                                                                                    โ†ฃ PrimitiveType: {  }                                                                               
   system.action.user_cancel_user_action:langcode                    Correct   Validatable   โœ…โœ…   NotNull: {  }                                                                                       
                                                                                                    Choice:                                                                                             
                                                                                                      callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'         
                                                                                                    โ†ฃ PrimitiveType: {  }                                                                               
   system.action.user_cancel_user_action:plugin                      Correct   Validatable   โœ…โœ…   PluginExists:                                                                                       
                                                                                                      manager: plugin.manager.action                                                                    
                                                                                                      interface: Drupal\Core\Action\ActionInterface                                                     
                                                                                                    โ†ฃ PrimitiveType: {  }                                                                               
   system.action.user_cancel_user_action:status                      Correct   Validatable   โœ…โœ…   โ†ฃ PrimitiveType: {  }                                                                               
   system.action.user_cancel_user_action:type                        Correct   NOT           โœ…โ“   โš ๏ธ  @todo Add validation constraints to config entity type: system.action.*                         
   system.action.user_cancel_user_action: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=system.action.user_cancel_user_action --detail --list-constraints

Proposed resolution

Add validation constraints to:

  1. system.action.*:type

Many tests creates actions by using only id and plugin.
Eg.

    $action = Action::create([
      'id' => 'entity_save_action',
      'plugin' => 'entity:save_action:entity_test_mul_changed',
    ]);
    $action->save();

or

    $action = Action::create([
      'id' => 'entity_delete_action',
      'plugin' => 'entity:delete_action:entity_test_mulrevpub',
    ]);
    $action->save();

These tests starts failing if we don't make type: nullable.

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
Systemย  โ†’

Last updated 7 days ago

No maintainer
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

  • Issue created by @narendraR
  • Merge request !8161Marked FullyValidatable โ†’ (Open) created by narendraR
  • Pipeline finished with Failed
    7 months ago
    Total: 541s
    #179973
  • Pipeline finished with Failed
    7 months ago
    Total: 538s
    #180156
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    ActionValidationTest needs to be updated now that it is fully validatable.

  • Pipeline finished with Failed
    7 months ago
    Total: 546s
    #184768
  • Pipeline finished with Failed
    7 months ago
    Total: 595s
    #184793
  • Pipeline finished with Success
    7 months ago
    Total: 511s
    #184845
  • Status changed to Needs review 7 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia narendraR Jaipur, India
  • Status changed to RTBC 7 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    This one seems pretty straight forward.

    I ran the test-only feature but everything passes but as a task am making the assumption the testing was previous just missing.

    Will mark.

  • Status changed to Needs work 7 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    It's not clear to me why type can be nullable, and this looks like a @todo in the issue summary. I checked a random site that has been through various updates and with some not exactly consistent contrib modules on it since early Drupal 8 days, and all the system.action config entities had type: set to something. This doesn't mean it absolutely shouldn't be nullable but it should be clear why (and maybe a comment in the YAML too if so).

  • Status changed to Needs review 7 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia narendraR Jaipur, India
  • Pipeline finished with Success
    7 months ago
    Total: 666s
    #189845
  • Status changed to RTBC 7 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Maybe a follow up to make it required?

    Feedback here seems to be addressed though.

  • Status changed to Needs work 7 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom alexpott ๐Ÿ‡ช๐Ÿ‡บ๐ŸŒ

    I've added a comment to the MR - I think this change introduces some questions for \Drupal\system\ActionConfigEntityInterface::getType()

  • Pipeline finished with Success
    6 months ago
    Total: 712s
    #203464
  • Pipeline finished with Canceled
    6 months ago
    Total: 207s
    #203549
  • Pipeline finished with Canceled
    6 months ago
    Total: 433s
    #203560
  • Pipeline finished with Success
    6 months ago
    #203567
  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia narendraR Jaipur, India

    Feedback addressed

  • Status changed to RTBC 6 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium borisson_ Mechelen, ๐Ÿ‡ง๐Ÿ‡ช

    We now have specific test coverage for a type that is null. This looks good to me.

  • Pipeline finished with Success
    6 months ago
    #215246
  • Status changed to Fixed 6 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom alexpott ๐Ÿ‡ช๐Ÿ‡บ๐ŸŒ

    Committed 9ddbc2c and pushed to 11.x. Thanks!

    • alexpott โ†’ committed 9ddbc2c7 on 11.x
      Issue #3449259 by narendraR, alexpott, catch, Wim Leers: Add validation...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024