You are here

class SocialUserNameConstraintValidator in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator
  2. 8.2 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator
  3. 8.3 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator
  4. 8.4 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator
  5. 8.5 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator
  6. 8.6 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator
  7. 8.7 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator
  8. 8.8 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator
  9. 10.3.x modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator
  10. 10.0.x modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator
  11. 10.1.x modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator
  12. 10.2.x modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator

Validates the UserName constraint no email address allowed in the username.

Hierarchy

Expanded class hierarchy of SocialUserNameConstraintValidator

1 file declares its use of SocialUserNameConstraintValidator
SocialUserNameConstraintTest.php in modules/social_features/social_user/tests/src/Unit/Validation/Constraint/SocialUserNameConstraintTest.php
1 string reference to 'SocialUserNameConstraintValidator'
social_user.services.yml in modules/social_features/social_user/social_user.services.yml
modules/social_features/social_user/social_user.services.yml
1 service uses SocialUserNameConstraintValidator
social_user.username_constraint in modules/social_features/social_user/social_user.services.yml
Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator

File

modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php, line 15

Namespace

Drupal\social_user\Plugin\Validation\Constraint
View source
class SocialUserNameConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
  protected $typedDataManager;

  /**
   * {@inheritdoc}
   */
  public function __construct(TypedDataManagerInterface $typed_data_manager) {
    $this->typedDataManager = $typed_data_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('typed_data_manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function validate($items, Constraint $constraint) {
    if (is_null($items)) {
      return;
    }
    if ($nameField = $items
      ->first()) {
      $name = $nameField
        ->__get('value');
      $definition = DataDefinition::create('string')
        ->setConstraints([
        'Email' => [],
      ]);
      $typed_data = $this->typedDataManager
        ->create($definition, $name);
      $violations = $typed_data
        ->validate();
      if (count($violations) == 0) {
        $this->context
          ->addViolation($constraint->usernameIsEmailMessage);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SocialUserNameConstraintValidator::$typedDataManager protected property
SocialUserNameConstraintValidator::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
SocialUserNameConstraintValidator::validate public function Checks if the passed value is valid.
SocialUserNameConstraintValidator::__construct public function