class UserNameValidator

Same name in other branches
  1. 10 core/modules/user/src/UserNameValidator.php \Drupal\user\UserNameValidator

Provides a username validator.

This validator re-uses the UserName constraint plugin but does not require a User entity.

Hierarchy

Expanded class hierarchy of UserNameValidator

3 files declare their use of UserNameValidator
SiteConfigureForm.php in core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php
UserNameValidatorTest.php in core/modules/user/tests/src/Kernel/UserNameValidatorTest.php
UserPasswordForm.php in core/modules/user/src/Form/UserPasswordForm.php
1 string reference to 'UserNameValidator'
user.services.yml in core/modules/user/user.services.yml
core/modules/user/user.services.yml
1 service uses UserNameValidator
user.name_validator in core/modules/user/user.services.yml
Drupal\user\UserNameValidator

File

core/modules/user/src/UserNameValidator.php, line 17

Namespace

Drupal\user
View source
class UserNameValidator {
    public function __construct(BasicRecursiveValidatorFactory $validatorFactory, ConstraintManager $constraintManager) {
    }
    
    /**
     * Validates a user name.
     *
     * @return \Symfony\Component\Validator\ConstraintViolationListInterface
     *   The list of constraint violations.
     */
    public function validateName(string $name) : ConstraintViolationListInterface {
        $validator = $this->validatorFactory
            ->createValidator();
        $constraint = $this->constraintManager
            ->create('UserName', []);
        return $validator->validate($name, $constraint);
    }

}

Members

Title Sort descending Modifiers Object type Summary
UserNameValidator::validateName public function Validates a user name.
UserNameValidator::__construct public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.