You are here

function apigee_edge_form_user_form_developer_email_validate in Apigee Edge 8

Validates whether the provided email address is already taken on Apigee Edge.

Parameters

array $form: Form array.

Drupal\Core\Form\FormStateInterface $form_state: Form state object.

1 string reference to 'apigee_edge_form_user_form_developer_email_validate'
apigee_edge_form_user_form_alter in ./apigee_edge.module
Implements hook_form_FORM_ID_alter().

File

./apigee_edge.module, line 732
Copyright 2018 Google Inc.

Code

function apigee_edge_form_user_form_developer_email_validate(array $form, FormStateInterface $form_state) {

  // If email address was changed.
  if ($form_state
    ->getValue('mail') !== $form_state
    ->getBuildInfo()['callback_object']
    ->getEntity()->mail->value) {
    $developer = NULL;
    try {
      $developer = Developer::load($form_state
        ->getValue('mail'));
    } 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.
    }
    if ($developer) {

      // Add email address to the whitelist because we would like to
      // display a custom error message instead of what this
      // field validation handler returns.
      DeveloperEmailUniqueValidator::whitelist($form_state
        ->getValue('mail'));
      if ($form_state
        ->getValue('administer_users')) {
        $form_state
          ->setErrorByName('mail', t('This email address already belongs to a developer on Apigee Edge.'));
      }
      else {
        $config = Drupal::config('apigee_edge.developer_settings');
        $form_state
          ->setErrorByName('mail', $config
          ->get('user_edit_error_message.value'));
      }
    }
  }
}