Problem/Motivation

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

./vendor/bin/drush config:inspect --filter-keys=core.entity_view_mode.taxonomy_term.full --detail --list-constraints --fields=key,validatability,constraints
➜  🤖 Analyzing…

 --------------------------------------------------------------------- ------------- --------------------------------------------------------------------------------------------- 
  Key                                                                   Validatable   Validation constraints                                                                       
 --------------------------------------------------------------------- ------------- --------------------------------------------------------------------------------------------- 
  core.entity_view_mode.taxonomy_term.full                              79%           ValidKeys: '<infer>'                                                                         
   core.entity_view_mode.taxonomy_term.full:                            Validatable   ValidKeys: '<infer>'                                                                         
   core.entity_view_mode.taxonomy_term.full:_core                       Validatable   ValidKeys:                                                                                   
                                                                                        - default_config_hash                                                                      
   core.entity_view_mode.taxonomy_term.full:_core.default_config_hash   Validatable   NotNull: {  }                                                                                
                                                                                      Regex: '/^[a-zA-Z0-9\-_]+$/'                                                                 
                                                                                      Length: 43                                                                                   
                                                                                      ↣ PrimitiveType: {  }                                                                        
   core.entity_view_mode.taxonomy_term.full:cache                       Validatable   ↣ PrimitiveType: {  }                                                                        
   core.entity_view_mode.taxonomy_term.full:dependencies                Validatable   ValidKeys: '<infer>'                                                                         
   core.entity_view_mode.taxonomy_term.full:dependencies.module         NOT           ❌ @todo Add validation constraints to ancestor type: config_dependencies                    
   core.entity_view_mode.taxonomy_term.full:dependencies.module.0       Validatable   NotBlank: {  }                                                                               
                                                                                      ExtensionName: {  }                                                                          
                                                                                      ExtensionExists: module                                                                      
                                                                                      ↣ PrimitiveType: {  }                                                                        
   core.entity_view_mode.taxonomy_term.full:description                 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_view_mode.taxonomy_term.full:id                          NOT           ⚠️  @todo Add validation constraints to config entity type: core.entity_view_mode.*.*        
   core.entity_view_mode.taxonomy_term.full:label                       Validatable   Regex:                                                                                       
                                                                                        pattern: '/([^\PC])/u'                                                                     
                                                                                        match: false                                                                               
                                                                                        message: 'Labels are not allowed to span multiple lines or contain control characters.'    
                                                                                      NotBlank: {  }                                                                               
                                                                                      ↣ PrimitiveType: {  }                                                                        
   core.entity_view_mode.taxonomy_term.full:langcode                    Validatable   NotNull: {  }                                                                                
                                                                                      Choice:                                                                                      
                                                                                        callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'  
                                                                                      ↣ PrimitiveType: {  }                                                                        
   core.entity_view_mode.taxonomy_term.full:status                      Validatable   ↣ PrimitiveType: {  }                                                                        
   core.entity_view_mode.taxonomy_term.full:targetEntityType            NOT           ⚠️  @todo Add validation constraints to config entity type: core.entity_view_mode.*.*        
   core.entity_view_mode.taxonomy_term.full:uuid                        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_view_mode.taxonomy_term.full --detail --list-constraints

Proposed resolution

Add validation constraints to:

  1. core.entity_view_mode.*.*:dependencies.module
  2. core.entity_view_mode.*.*:id
  3. core.entity_view_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-3445150

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.

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

narendrar’s picture

Status: Active » Needs review
narendrar’s picture

wim leers’s picture

Status: Needs review » Needs work
Issue tags: +Portland2024

Nice progress here! 😄 Still needs some work, but for each of the things that still need to be addressed, there's prior art/patterns to look at 😊

carsoncho’s picture

Assigned: Unassigned » carsoncho
carsoncho’s picture

carsoncho’s picture

Assigned: carsoncho » Unassigned
carsoncho’s picture

carsoncho’s picture

carsoncho’s picture

What I think is remaining is the tests updates. I see there's a few failing due to configuration tests as it's noting that the core.entity_view_mode.* config files have been changed and updated. This is to be expected given the hook_post_update_NAME() being included here.

Drupal\FunctionalTests\Installer\InstallerExistingConfigMultilingualTest::testConfigSync
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     'create' => []
     'update' => Array (
-        0 => 'system.mail'
+        0 => 'core.entity_view_mode.node.teaser'
+        1 => 'core.entity_view_mode.node.se...result'
+        2 => 'core.entity_view_mode.node.se..._index'
+        3 => 'core.entity_view_mode.node.rss'
+        4 => 'core.entity_view_mode.node.full'
+        5 => 'system.mail'
+        6 => 'core.entity_view_mode.user.full'
+        7 => 'core.entity_view_mode.user.compact'
     )

Is the right thing to do here update the tests so they expect all those view mode configuration changes? Testing is an area I'd like to be able to contribute to more so any information folks can provide is much appreciated.

narendrar’s picture

Status: Needs work » Needs review
Issue tags: -Needs update path, -Needs update path tests

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

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new397.61 KB

Replied to the comment and applied 2 nitpicky things

On a 11.x setup with standard install there are several view modes across entity types
Applied the MR locally
Update hook ran without issue

Manually downloaded config inspector and am seeing fully validated entity_view_modes

validated

catch’s picture

Status: Reviewed & tested by the community » Needs work

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

narendrar’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new14.94 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. 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.

narendrar’s picture

Status: Needs work » Needs review
narendrar’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record
narendrar’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record
wim leers’s picture

Status: Needs review » Needs work

Thanks for your continued contributions in the config validation space, @carsoncho! 🙏😊

A few nits, and one question about a comment that seems wrong.

The MR itself looks great! 👍

narendrar’s picture

Status: Needs work » Needs review

Updating description to 'description' => NULL is giving depreciation error. Other feedback addressed.

narendrar’s picture

Feedback addressed.

wim leers’s picture

Status: Needs review » Needs work

Updating description to 'description' => NULL is giving depreciation error.

The deprecation error you're seeing is literally the one this MR is adding.

Why does that deprecation exist here? node_node_type_presave() doesn't do that (introduced in #2002174: Allow vocabularies to be validated via the API, not just during form submissions.) Ah … because @catch asked for that.

Well, now we've got ourselves a chicken-egg situation. 😅

The only way I see out of this is to not rely on the presave hook to perform the update, but instead to duplicate that logic into the update hook.

narendrar’s picture

Re #25, Does it mean removing system_entity_view_mode_presave() from system.module and doing $view_mode->set('description', NULL)->save(); in system_post_update_convert_empty_string_entity_view_modes_to_null of system.post_update.php. Also where should we use @trigger_error in this case or it can be avoided?

When I did as above it gives Schema errors for core.entity_view_mode.node.teaser with the following errors: 0 [description] This value should not be blank.

narendrar’s picture

Status: Needs work » Needs review
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.

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

bbrala’s picture

Next up, this needs a little word making sure the fixture/config* is updated to reflect some of the config changes.

bbrala’s picture

Still some test errors left in biuld/jsonapi and randomjs kinda test.

bbrala’s picture

My contribution in code was minimal, mostly rebasing and small fix to make sure it still validates. One hook needs converting to an OOP hook since this has been open for so long.

If noone else does, i can move the code, think i can even still RTBC after that since it doesnt really introduce code.

bbrala’s picture

Status: Needs work » Reviewed & tested by the community

Going to go out on a limb and RTBC since i only rebased and fix codestyle/phpstan issues and didnt really write new code.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new20.03 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. 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

I think the review bot is wrong, the text file also stated no errors. Still merged 11.x again though.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new20.03 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. 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
Issue tags: +no-needs-review-bot

Go away nr bot.

borisson_’s picture

Status: Reviewed & tested by the community » Needs work

The last run on the mr has a phpcs failure, let's fix that.

borisson_’s picture

The changes that are done look good though, I think they all make sense.

bbrala’s picture

Status: Needs work » Needs review

Fixed the phpcs issues.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

I think this is good, I can't find any changes I'd make to this issue anymore.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

We need to update the deprecations to 11.3.x plus I think the hook this MR adds does not have the correct info the annotation.

bbrala’s picture

Status: Needs work » Needs review

I think we should skip the null changes. Me, @longwave, @phenaproxima, @berdir talked about this on slack and it will remove a lot of the hurdles to move forward with these kinda of issues. Just compare the changes of

#13904 and #7906 the difference is insane.

Gonna go our on a limb and NR this with the minimized changes. (IS seems to cover current approach still :P)

Edit: updated contribution record.

bbrala’s picture

Just thinking, we could argue that we still need the presave to make saving either '' or null always, so it will be eventually consistent. But not sure if that is worth the hook.

borisson_’s picture

Just thinking, we could argue that we still need the presave to make saving either '' or null always, so it will be eventually consistent. But not sure if that is worth the hook.

Consistency is a big goal of increasing the strictness in my opinion, I think that's worth the hook.

bbrala’s picture

Thats a small change, i can do that.

bbrala’s picture

Which do you prefer as the default. '' or NULL? Id probably opt for ''

edit: added the hook

bbrala’s picture

Hmm, with '' it is all green since that has been the default for aw hile now.

With NULL we do have failing tests that expect ''.

smustgrave’s picture

Status: Needs review » Needs work
   ├ Failed asserting that two arrays are equal.
       ┊ ---·Expected
       ┊ +++·Actual
       ┊ @@ @@
       ┊  Array (
       ┊      'create' => []
       ┊      'update' => Array (
       ┊ -········0·=>·'system.mail'
       ┊ +········0·=>·'core.entity_view_mode.node.teaser'
       ┊ +········1·=>·'core.entity_view_mode.node.se...result'
       ┊ +········2·=>·'core.entity_view_mode.node.se..._index'
       ┊ +········3·=>·'core.entity_view_mode.node.rss'
       ┊ +········4·=>·'core.entity_view_mode.node.full'
       ┊ +········5·=>·'system.mail'
       ┊ +········6·=>·'core.entity_view_mode.user.full'
       ┊ +········7·=>·'core.entity_view_mode.user.compact'
       ┊      )
       ┊      'delete' => []
       ┊      'rename' => []

Most of the tests appear to be failing with something like this. Possibly due to the presave hook?

bbrala’s picture

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.