Problem/Motivation

Form modes have 3 property paths that are not yet validatable:

vendor/bin/drush config:inspect --filter-keys=core.entity_form_mode.user.register --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                                                                       
 ---------------------------------------------------------------- --------- ------------- ------ --------------------------------------------------------------------------------------------- 
  core.entity_form_mode.user.register                              Correct   79%           ✅❓   ValidKeys: '<infer>'                                                                         
   core.entity_form_mode.user.register:                            Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                                         
   core.entity_form_mode.user.register:_core                       Correct   Validatable   ✅✅   ValidKeys:                                                                                   
                                                                                                    - default_config_hash                                                                      
   core.entity_form_mode.user.register:_core.default_config_hash   Correct   Validatable   ✅✅   NotNull: {  }                                                                                
                                                                                                  Regex: '/^[a-zA-Z0-9\-_]+$/'                                                                 
                                                                                                  Length: 43                                                                                   
                                                                                                  ↣ PrimitiveType: {  }                                                                        
   core.entity_form_mode.user.register:cache                       Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }                                                                        
   core.entity_form_mode.user.register:dependencies                Correct   Validatable   ✅✅   ValidKeys: '<infer>'                                                                         
   core.entity_form_mode.user.register:dependencies.module         Correct   NOT           ✅❓   ❌ @todo Add validation constraints to ancestor type: config_dependencies                    
   core.entity_form_mode.user.register:dependencies.module.0       Correct   Validatable   ✅✅   NotBlank: {  }                                                                               
                                                                                                  ExtensionName: {  }                                                                          
                                                                                                  ExtensionExists: module                                                                      
                                                                                                  ↣ PrimitiveType: {  }                                                                        
   core.entity_form_mode.user.register:description                 Correct   Validatable   ✅✅   Regex:                                                                                       
                                                                                                    pattern: '/([^\PC\x09\x0a\x0d])/u'                                                         
                                                                                                    match: false                                                                               
                                                                                                    message: 'Text is not allowed to contain control characters, only visible characters.'     
                                                                                                  ↣ PrimitiveType: {  }                                                                        
   core.entity_form_mode.user.register:id                          Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints to config entity type: core.entity_form_mode.*.*        
   core.entity_form_mode.user.register:label                       Correct   Validatable   ✅✅   Regex:                                                                                       
                                                                                                    pattern: '/([^\PC])/u'                                                                     
                                                                                                    match: false                                                                               
                                                                                                    message: 'Labels are not allowed to span multiple lines or contain control characters.'    
                                                                                                  NotBlank: {  }                                                                               
                                                                                                  ↣ PrimitiveType: {  }                                                                        
   core.entity_form_mode.user.register:langcode                    Correct   Validatable   ✅✅   NotNull: {  }                                                                                
                                                                                                  Choice:                                                                                      
                                                                                                    callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'  
                                                                                                  ↣ PrimitiveType: {  }                                                                        
   core.entity_form_mode.user.register:status                      Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }                                                                        
   core.entity_form_mode.user.register:targetEntityType            Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints to config entity type: core.entity_form_mode.*.*        
   core.entity_form_mode.user.register: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=core.entity_form_mode.user.register --detail --list-constraints

Proposed resolution

Add validation constraints to:

  1. core.entity_form_mode.*.*:dependencies.module
  2. core.entity_form_mode.*.*:id
  3. core.entity_form_mode.*.*:targetEntityType

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.

Issue fork drupal-3448457

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

narendraR created an issue. See original summary.

narendrar’s picture

Status: Needs work » Needs review
Related issues: +#3445150: Add validation constraints to core.entity_view_mode.*.*

smustgrave made their first commit to this issue’s fork.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new76.83 KB

Applied some nitpicky typehint return voids

Applied the MR to a 11.x install using standard profile
Believe the only entity_form_mode is for core.entity_form_mode.user.register
Ran updb and hook ran without issue

Manually downloaded config_inspector to 11.x setup and confirmed seeing fully validatable now

validate

catch’s picture

Status: Reviewed & tested by the community » Needs work

One issue with the presave hook on the MR - missing a deprecation notice. #3443942: Add proper deprecation notices in config entity presave bc layers has more details.

narendrar’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Left some comments on MR.

narendrar’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Deprecation appears to be correct to me.

catch’s picture

Status: Reviewed & tested by the community » Needs work

One small comment on the deprecation message. Hard to fit this sort of thing into the standard format.

narendrar’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Message seems good

larowlan’s picture

Status: Reviewed & tested by the community » Needs review

Left one question on the MR, great work here - bit more involved with the update hook!

narendrar’s picture

This issue is ready for re-review. I have added the return FALSE. Thanks

phenaproxima’s picture

Status: Needs review » Needs work

Looks okay but I have a couple of questions here.

narendrar’s picture

Status: Needs work » Needs review
phenaproxima’s picture

Status: Needs review » Needs work

Only one tiny thing and then I think this looks good.

narendrar’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new100.01 KB

config

Applied MR on a standard install for 11.x with config inspector and getting all green checks.

Looking at MR 8135 and from what I can tell all feedback has been addressed.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

If I go to admin/structure/display-modes/form/ and edit the user registration form and save the form mode with no description then the system_entity_form_mode_presave() will trigger a deprecation notice.

We need to add something to the form to convert empty strings to NULLs... normally we'd say use #config_target but we've not worked out how to using #config_target like stuff with config entities yet.

narendrar’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Tested the scenario in #21 has been addressed with https://git.drupalcode.org/project/drupal/-/merge_requests/8135/diffs?co...

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

I'm not sure that a NULL description is any better then an empty string. Do we think that this part of the change is actually worth it?

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

phenaproxima’s picture

Assigned: Unassigned » wim leers

I'm not sure that a NULL description is any better then an empty string. Do we think that this part of the change is actually worth it?

I don't feel strongly one way or the other, so I'm assigning this to Wim for input. I suspect he has a clearer reason why NULL would be useful here.

bbrala’s picture

Going through the config issues a bit to see where things are hanging.

I read through all this, and have not seen any discussion around the NULL change. I understand the text in the CR ("The reason is because an empty string makes no sense for this field. "" is never a useful description of a form mode."). But I dont really see why this is as much better as it is a change.

If i try to argue why it should be null: Now i want no desription is equal to en empty description. This unfortunately meant he field is not really optional, when you wouldn't post an description you technically tend a NULL, which cannot be stored right now. But if we allow null, we would be able to save without the field, since null is fine.

This could have reasons in jsonapi, maybe we can then post without the field and make it null, instead of requiring an empty string. This is as far as i get. But does make me beleive null is a good idea.

bbrala’s picture

Assigned: wim leers » Unassigned
Status: Needs work » Reviewed & tested by the community

Removing wim from assignment, that will probably not make this go faster.

My conclusion in #27 is that null is a good idea. I rebased and if tests don't fail I think this can move forward as is. Since my additions were minimal, setting RTBC.

bbrala’s picture

Status: Reviewed & tested by the community » Needs work

Seems fixtures might need work. Not sure how those work.

bbrala’s picture

Status: Needs work » Reviewed & tested by the community
borisson_’s picture

Found the tiniest of nitpicks, this is just a version number change in the deprecation, so leaving at rtbc.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

bbrala’s picture

Status: Needs work » Reviewed & tested by the community

Rebaed.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

We need to move the hook implementation to the correct new OOP place... \Drupal\system\Hook\SystemHooks

bbrala’s picture

Thanks, you are right. By now we have the OOP hooks. I think this issue is present in the other validation issues also. I'll do a round.

bbrala’s picture

Status: Needs work » Reviewed & tested by the community

I think this change is so minimal i can RTBC again. I ran the upgrade test after moving the hook code to SystemHooks.php and it upgraded fine.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 4f3432b and pushed to 11.x. Thanks!

  • alexpott committed 4f3432bf on 11.x
    Issue #3448457 by narendrar, bbrala, smustgrave, alexpott, phenaproxima...
bbrala’s picture

CR was out of date regarding versions, does it need publishing also? Probably?

quietone’s picture

I'll take the 'probably' as a 'yes'. I have updated and published the CR.

bbrala’s picture

Hehe yeah, it would need publishing, ty. Didn't want to do it myself for possible text issues.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.