Problem/Motivation
User role entity is not yet fully validatable:
./vendor/bin/drush config:inspect --filter-keys=user.role.anonymous --detail --list-constraints --fields=key,validatability,constraints
➜ 🤖 Analyzing…
------------------------------------------------ ------------- ---------------------------------------------------------------------------------------------
Key Validatable Validation constraints
------------------------------------------------ ------------- ---------------------------------------------------------------------------------------------
user.role.anonymous 66% ValidKeys: '<infer>'
user.role.anonymous: Validatable ValidKeys: '<infer>'
user.role.anonymous:_core Validatable ValidKeys:
- default_config_hash
user.role.anonymous:_core.default_config_hash Validatable NotNull: { }
Regex: '/^[a-zA-Z0-9\-_]+$/'
Length: 43
↣ PrimitiveType: { }
user.role.anonymous:dependencies Validatable ValidKeys: '<infer>'
user.role.anonymous:dependencies.config NOT ❌ @todo Add validation constraints to ancestor type: config_dependencies
user.role.anonymous:dependencies.config.0 Validatable NotBlank: { }
ConfigExists: { }
↣ PrimitiveType: { }
user.role.anonymous:dependencies.module NOT ❌ @todo Add validation constraints to ancestor type: config_dependencies
user.role.anonymous:dependencies.module.0 Validatable NotBlank: { }
ExtensionName: { }
ExtensionExists: module
↣ PrimitiveType: { }
user.role.anonymous:dependencies.module.1 Validatable NotBlank: { }
ExtensionName: { }
ExtensionExists: module
↣ PrimitiveType: { }
user.role.anonymous:dependencies.module.2 Validatable NotBlank: { }
ExtensionName: { }
ExtensionExists: module
↣ PrimitiveType: { }
user.role.anonymous:dependencies.module.3 Validatable NotBlank: { }
ExtensionName: { }
ExtensionExists: module
↣ PrimitiveType: { }
user.role.anonymous:dependencies.module.4 Validatable NotBlank: { }
ExtensionName: { }
ExtensionExists: module
↣ PrimitiveType: { }
user.role.anonymous:dependencies.module.5 Validatable NotBlank: { }
ExtensionName: { }
ExtensionExists: module
↣ PrimitiveType: { }
user.role.anonymous:dependencies.module.6 Validatable NotBlank: { }
ExtensionName: { }
ExtensionExists: module
↣ PrimitiveType: { }
user.role.anonymous:id Validatable Regex:
pattern: '/^[a-z0-9_]+$/'
message: 'The %value machine name is not valid.'
Length:
max: 166
↣ PrimitiveType: { }
user.role.anonymous:is_admin Validatable ↣ PrimitiveType: { }
user.role.anonymous:label Validatable Regex:
pattern: '/([^\PC])/u'
match: false
message: 'Labels are not allowed to span multiple lines or contain control characters.'
NotBlank: { }
↣ PrimitiveType: { }
user.role.anonymous:langcode Validatable NotNull: { }
Choice:
callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'
↣ PrimitiveType: { }
user.role.anonymous:permissions NOT ⚠️ @todo Add validation constraints to config entity type: user.role.*
user.role.anonymous:permissions.0 NOT ⚠️ @todo Add validation constraints to config entity type: user.role.*
user.role.anonymous:permissions.1 NOT ⚠️ @todo Add validation constraints to config entity type: user.role.*
user.role.anonymous:permissions.2 NOT ⚠️ @todo Add validation constraints to config entity type: user.role.*
user.role.anonymous:permissions.3 NOT ⚠️ @todo Add validation constraints to config entity type: user.role.*
user.role.anonymous:permissions.4 NOT ⚠️ @todo Add validation constraints to config entity type: user.role.*
user.role.anonymous:permissions.5 NOT ⚠️ @todo Add validation constraints to config entity type: user.role.*
user.role.anonymous:permissions.6 NOT ⚠️ @todo Add validation constraints to config entity type: user.role.*
user.role.anonymous:status Validatable ↣ PrimitiveType: { }
user.role.anonymous:uuid Validatable Uuid: { }
↣ PrimitiveType: { }
user.role.anonymous:weight Validatable Range:
min: -2147483648
max: 2147483647
FullyValidatable: null
↣ PrimitiveType: { }
------------------------------------------------ ------------- ---------------------------------------------------------------------------------------------
Steps to reproduce
- Get a local git clone of Drupal core
11.x. 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!)composer require drush/drushvendor/bin/drush config:inspect --filter-keys=user.role.anonymous --detail --list-constraints
Proposed resolution
Add validation constraints to missing properties.
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.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | Screenshot 2024-05-07 at 10.09.37 AM.png | 70.5 KB | smustgrave |
Issue fork drupal-3445215
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
Comment #3
narendrarComment #4
smustgrave commentedUsing configuration inspector on a standard install I see
So believe this one is good.
Comment #5
wim leersI don't see any justification for making
is_adminandweightoptional values? I kinda getweightbeing optional … but notis_admin.Plus, if they're optional, then that should be reflected on the class properties too, and that's not the case:
+
Comment #8
mtiftComment #9
wim leersComment #10
mtiftComment #11
wim leersOne very small tweak and this will be ready: https://git.drupalcode.org/project/drupal/-/merge_requests/7910#note_317349
Comment #12
mikelutzDone.
Comment #13
smustgrave commentedFeedback appears to be addressed.
Comment #14
alexpottAdded some review comments. I'm not sure about the nullability being added here.
Comment #15
mtift@alexpott I don't see any comments. Did you add them on https://git.drupalcode.org/project/drupal/-/merge_requests/7910?
Comment #16
mtiftComment #17
smustgrave commentedMR appears to have a large number of failures.
Comment #18
borisson_Looks like a lot of the current failures are because of invalid configuration in tests.
Comment #19
borisson_Discussed with @alexpott at drupal dev days, setting default values on the entity.
Comment #20
borisson_The remaining failures are all in rest, but I don't understand how to fix them.
Comment #21
borisson_Hurrah, it's green.
Comment #22
smustgrave commentedFeedback appears to be addressed for this one.
Comment #23
alexpottCommitted f4ae13d and pushed to 11.x. Thanks!
Comment #26
xjmAforementioned Portland discussion. Remember to add credits for in-person discussions, folks!