You are here

public function SocialUserNameConstraintValidator::validate in Open Social 10.0.x

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::validate()
  2. 8 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator::validate()
  3. 8.2 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator::validate()
  4. 8.3 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator::validate()
  5. 8.4 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator::validate()
  6. 8.5 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator::validate()
  7. 8.6 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator::validate()
  8. 8.7 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator::validate()
  9. 8.8 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator::validate()
  10. 10.3.x modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator::validate()
  11. 10.1.x modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator::validate()
  12. 10.2.x modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator::validate()

File

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

Class

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

Namespace

Drupal\social_user\Plugin\Validation\Constraint

Code

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);
    }
  }
}