Problem/Motivation
user_validate_name() uses the type data system in order to validate a simple name. This introduces complexity as we discovered in #3431200: FieldItemList::getConstraints() incorrectly sets $maxMessage as TranslatableMarkup where FieldItemList is adding a Count field constraint that is unrelated to this UserName validation.
Steps to reproduce
Proposed resolution
Deprecate user_validate_name() and use the basic validator that does not require the typed data system.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3431203
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:
- 3431203-deprecate-uservalidatename-and
changes, plain diff MR !7069
Comments
Comment #3
kim.pepperComment #4
longwaveUserPasswordForm has a copy-paste of user_validate_name() that could also be replaced here:
Comment #5
smustgrave commentedHave not reviewed
But appears to have several test failures.
Comment #6
kim.pepperThanks for the reviews. I feel like this could be simpler if we didn't need to use typed data as we are not validating an entity, but
\Drupal\user\Plugin\Validation\Constraint\UserNameConstraintValidatorassumes it is. 🤷Also, since we are only checking the name, I think we can rename it to UserNameValidator.
Comment #7
smustgrave commentedSearched for user_validate_name() and appears all instances have been replaced.
Based on the small number in core assume that D11 should be fine for removal vs D12.
Test coverage can be seen here https://git.drupalcode.org/issue/drupal-3431203/-/jobs/1099143
Comment #8
alexpottI've added some review comments to address - thanks!
Comment #9
kim.pepperAddressed feedback.
Comment #10
kim.pepperHad a look for docs that say we require a
@returnannotation and couldn't find one. Only docs for describing the format of the@returnannotation. https://www.drupal.org/docs/develop/standards/php/api-documentation-and-...Comment #11
smustgrave commentedFor the @return statement. If phpcs doesn't complain about it being included think it can't hurt.
Comment #12
kim.pepperAddressed feedback.
Comment #13
smustgrave commentedFeedback appears to be addressed.
Comment #14
alexpottGiven where we are in the release cycle and the number of usages I think we should push the deprecation of user_validate_name out to 12. See https://git.drupalcode.org/search?group_id=2&repository_ref=&scope=blobs...
Also I think we should update the code to call the new service for consistency.
Comment #15
alexpottPushed the minor tweaks for #14
Comment #16
alexpottCommitted 8e7d3e0 and pushed to 11.x. Thanks!
Committed 3194f76 and pushed to 10.3.x. Thanks!