Deprecate user_validate_name() and replace with service

Created on 18 March 2024, 6 months ago
Updated 24 April 2024, 5 months ago

Problem/Motivation

user_validate_name() uses the type data system in order to validate a simple name. This introduces complexity as we discovered in πŸ› FieldItemList::getConstraints() incorrectly sets $maxMessage as TranslatableMarkup Active 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

πŸ“Œ Task
Status

Fixed

Version

10.3 ✨

Component
User moduleΒ  β†’

Last updated 1 day ago

Created by

πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @kim.pepper
  • Status changed to Needs review 6 months ago
  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia
  • Pipeline finished with Failed
    6 months ago
    Total: 150s
    #121980
  • Pipeline finished with Failed
    6 months ago
    Total: 279s
    #121982
  • Pipeline finished with Failed
    6 months ago
    Total: 435s
    #122035
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    UserPasswordForm has a copy-paste of user_validate_name() that could also be replaced here:

        // First, see if the input is possibly valid as a username.
        $name = trim($form_state->getValue('name'));
        $definition = BaseFieldDefinition::create('string')
          ->addConstraint('UserName', []);
        $data = $this->typedDataManager->create($definition);
        $data->setValue($name);
        $violations = $data->validate();
        // Usernames have a maximum length shorter than email addresses. Only print
        // this error if the input is not valid as a username or email address.
        if ($violations->count() > 0 && !$this->emailValidator->isValid($name)) {
    
  • Status changed to Needs work 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Have not reviewed

    But appears to have several test failures.

  • Pipeline finished with Success
    6 months ago
    Total: 495s
    #122776
  • Pipeline finished with Success
    6 months ago
    Total: 677s
    #122787
  • Status changed to Needs review 6 months ago
  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    Thanks 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\UserNameConstraintValidator assumes it is. 🀷

    Also, since we are only checking the name, I think we can rename it to UserNameValidator.

  • Pipeline finished with Success
    6 months ago
    Total: 2925s
    #122794
  • Pipeline finished with Canceled
    6 months ago
    Total: 374s
    #122861
  • Pipeline finished with Success
    6 months ago
    Total: 480s
    #122871
  • Pipeline finished with Failed
    6 months ago
    Total: 172s
    #122881
  • Pipeline finished with Failed
    6 months ago
    Total: 490s
    #122890
  • Pipeline finished with Success
    6 months ago
    Total: 572s
    #122900
  • Status changed to RTBC 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Searched 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

  • Pipeline finished with Success
    5 months ago
    Total: 574s
    #133995
  • Status changed to Needs work 5 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    I've added some review comments to address - thanks!

  • Pipeline finished with Success
    5 months ago
    Total: 578s
    #134968
  • Status changed to Needs review 5 months ago
  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    Addressed feedback.

  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    Had a look for docs that say we require a @return annotation and couldn't find one. Only docs for describing the format of the @return annotation. https://www.drupal.org/docs/develop/standards/php/api-documentation-and-... β†’

  • Pipeline finished with Success
    5 months ago
    #134972
  • Status changed to Needs work 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    For the @return statement. If phpcs doesn't complain about it being included think it can't hurt.

  • Pipeline finished with Canceled
    5 months ago
    Total: 38s
    #138198
  • Status changed to Needs review 5 months ago
  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    Addressed feedback.

  • Status changed to RTBC 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Feedback appears to be addressed.

  • Pipeline finished with Success
    5 months ago
    Total: 632s
    #138199
  • Status changed to Needs work 5 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Given 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.

  • Status changed to RTBC 5 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Pushed the minor tweaks for #14

  • Pipeline finished with Success
    5 months ago
    #138445
  • Status changed to Fixed 5 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Committed 8e7d3e0 and pushed to 11.x. Thanks!
    Committed 3194f76 and pushed to 10.3.x. Thanks!

    • alexpott β†’ committed 3194f768 on 10.3.x
      Issue #3431203 by kim.pepper, alexpott, smustgrave, longwave: Deprecate...
    • alexpott β†’ committed 8e7d3e0f on 11.x
      Issue #3431203 by kim.pepper, alexpott, smustgrave, longwave: Deprecate...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024