SocialUserNameConstraintValidator.php in Open Social 8.4
Same filename and directory in other branches
- 8.9 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php
- 8 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php
- 8.2 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php
- 8.3 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php
- 8.5 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php
- 8.6 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php
- 8.7 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php
- 8.8 modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php
- 10.3.x modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php
- 10.0.x modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php
- 10.1.x modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php
- 10.2.x modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.php
File
modules/social_features/social_user/src/Plugin/Validation/Constraint/SocialUserNameConstraintValidator.phpView source
<?php
namespace Drupal\social_user\Plugin\Validation\Constraint;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* Validates the UserName constraint no email address allowed in the username.
*/
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);
}
}
}
}
Classes
Name | Description |
---|---|
SocialUserNameConstraintValidator | Validates the UserName constraint no email address allowed in the username. |