Comment type entity is not yet fully validatable:

./vendor/bin/drush config:inspect --filter-keys=comment.type.comment --detail --list-constraints --fields=key,validatability,constraints

>  🤖 Analyzing…

 ------------------------------------------------- ------------- ---------------------------------------------------------------------- 
  Key                                               Validatable   Validation constraints                                                
 ------------------------------------------------- ------------- ---------------------------------------------------------------------- 
  comment.type.comment                              91%           ValidKeys: '<infer>'                                                  
   comment.type.comment:                            Validatable   ValidKeys: '<infer>'                                                  
   comment.type.comment:_core                       Validatable   ValidKeys:                                                            
                                                                    - default_config_hash                                               
   comment.type.comment:_core.default_config_hash   Validatable   NotNull: {  }                                                         
                                                                  Regex: '/^[a-zA-Z0-9\-_]+$/'                                          
                                                                  Length: 43                                                            
                                                                  ↣ PrimitiveType: {  }                                                 
   comment.type.comment:dependencies                Validatable   ValidKeys: '<infer>'                                                  
   comment.type.comment:description                 Validatable   Regex:                                                                
                                                                    pattern: '/([^\PC\x09\x0a\x0d])/u'                                  
                                                                    match: false                                                        
                                                                    message: 'Text is not allowed to contain control characters, only   
                                                                  visible characters.'                                                  
                                                                  ↣ PrimitiveType: {  }                                                 
   comment.type.comment:id                          Validatable   Regex:                                                                
                                                                    pattern: '/^[a-z0-9_]+$/'                                           
                                                                    message: 'The %value machine name is not valid.'                    
                                                                  Length:                                                               
                                                                    max: 166                                                            
                                                                  ↣ PrimitiveType: {  }                                                 
   comment.type.comment:label                       Validatable   Regex:                                                                
                                                                    pattern: '/([^\PC])/u'                                              
                                                                    match: false                                                        
                                                                    message: 'Labels are not allowed to span multiple lines or contain  
                                                                  control characters.'                                                  
                                                                  NotBlank: {  }                                                        
                                                                  ↣ PrimitiveType: {  }                                                 
   comment.type.comment:langcode                    Validatable   NotNull: {  }                                                         
                                                                  Choice:                                                               
                                                                    callback:                                                           
                                                                  'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllVali  
                                                                  dLangcodes'                                                           
                                                                  ↣ PrimitiveType: {  }                                                 
   comment.type.comment:status                      Validatable   ↣ PrimitiveType: {  }                                                 
   comment.type.comment:target_entity_type_id       NOT           ⚠️  @todo Add validation constraints to config entity type:           
                                                                  comment.type.*                                                        
   comment.type.comment: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=comment.type.comment --detail --list-constraints

Proposed resolution

Add validation constraints to missing properties.

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

More validation 🚀

Release notes snippet

None.

Issue fork drupal-3455066

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

mtift created an issue. See original summary.

mtift’s picture

Issue summary: View changes

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

mtift’s picture

Assigned: mtift » Unassigned
borisson_’s picture

This requires us to add something like EntityTypeExistsValidator, currently working on that.

borisson_’s picture

Spellcheck fails, but not sure how to better name this.

borisson_’s picture

Status: Active » Needs review
Issue tags: +DevDaysBurgas2024
smustgrave’s picture

Status: Needs review » Needs work

MR appears to have phpcs errors.

pooja_sharma’s picture

I have observed the test failures, may be we can use:

"commentAccepted/commentEligible/commentAllowed" in place of "Commentable"

As "commentAccepted/commentEligible/commentAllowed" word would be more closer/relative to the "Commentable" word to fix cspell test failures.

Left suggestion not updating MR, as most of the work done already.

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

bbrala’s picture

Status: Needs work » Needs review

Commentable makes so much sense i dont want to change it, just added to the drupal words. THink this can go back to NR

bbrala’s picture

Status: Needs review » Needs work

Seems a test is still fialing since it expects a string, not null.

bbrala’s picture

edit: Seems the message is more generic, when an entity doesnt use interger id, it doesn't validate as commentable. Which makes sense, the error is just not adjusted to that situation

bbrala’s picture

Ok, so the issue remaining is the fact that in ConfigEntityValidationTestBase::testRequiredPropertyValuesMissing it tries to test what happens when a property is set to null. When EntityTypeExistsConstraintValidator is validated it also executes the code:

    if (!is_string($value)) {
      throw new UnexpectedTypeException($value, 'string');
    }

Which is then thrown. When looking at other implementations where this eror is thrown i see ContentLanguageSettings with EntityBundleExists. This sems to be an immutable property.

I'm now guessing there is 2 possible solutions:

1. The target_entity_type_id property of the comment type should be immutable.
2. It is not immutable, but instead of throwing an UnexpectedTypeException is might just need to add a validation error that the property shhould be string.

What the right solution is, i dont know. Hopefully someone does :x

bbrala’s picture

Did some digging. Ended up removing the exception and checking for null and '' in IsCommentable and EntityTypeExists. Seems to make more sense. Also adjusted the test so it expects extra validation errors when looking for null.

bbrala’s picture

Status: Needs work » Needs review

All green.

borisson_’s picture

I think this looks good, there's no way I can rtbc this issue, because I wrote part of it.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative
StatusFileSize
new23.28 KB
new25.64 KB

Before

before

After

after

"EntityTypeExists" We actually used a similar constraint in book contrib so glad to see this is going to be part of core.

Did a review of the code changes and nothing stands out and comments appear to be functioning just fine (11.x standard profile install locally).

LGTM

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

Conflict was on cspell word list. Rebased, keeping 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
Issue tags: +no-needs-review-bot

This was a clean rebase. Not sure why its confused.

bbrala’s picture

Added CR

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Added some nits to the MR.

bbrala’s picture

Fixed a few issues, but still need to make the constraint container aware to inject the entitty type manager and use that in the validator.

bbrala’s picture

Think nullanble is not allow, but willl cycle back later.

bbrala’s picture

Status: Needs work » Needs review

All green after cleanup. But to much to set rtbc right away

bbrala’s picture

Status: Needs review » Needs work
bbrala’s picture

Status: Needs work » Needs review

Unrealted failure, all good imo.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Looks like all the remarks by longwave have been resolved.

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Looks good, one question about the placement of IsCommentableConstraint.

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.