public function DeveloperEmailUniqueValidator::validate in Apigee Edge 8
File
- src/
Plugin/ Validation/ Constraint/ DeveloperEmailUniqueValidator.php, line 62
Class
- DeveloperEmailUniqueValidator
- Checks if an email address already belongs to a developer on Edge.
Namespace
Drupal\apigee_edge\Plugin\Validation\ConstraintCode
public function validate($items, Constraint $constraint) {
if (in_array($items->value, static::$whitelist)) {
return;
}
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $items
->getEntity();
// If field's value has not changed do not validate it.
if (!$entity
->isNew()) {
$original = $this->entityTypeManager
->getStorage($entity
->getEntityType()
->id())
->load($entity
->id());
if ($original->{$items
->getName()}->value === $items->value) {
return;
}
}
try {
$developer = Developer::load($items->value);
if ($developer) {
$this->context
->addViolation($constraint->message, [
'%email' => $items->value,
]);
}
} catch (\Exception $exception) {
// Nothing to do here, if there is no connection to Apigee Edge interrupt
// the registration in the
// apigee_edge_form_user_form_api_connection_validate() function.
}
}