You are here

public function BakeryPullForm::validateForm in Bakery Single Sign-On System 8.2

Make sure we are not trying to request an existing user.

Overrides FormBase::validateForm

File

src/Forms/BakeryPullForm.php, line 65

Class

BakeryPullForm
Contribute form.

Namespace

Drupal\bakery\Forms

Code

public function validateForm(array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\user\UserInterface|false $existing_account */
  $existing_account = user_load_by_name($form_state
    ->getValue('name'));
  if (!$existing_account && $form_state
    ->getValue('or_email')) {

    /** @var \Drupal\user\UserInterface|false $existing_account */
    $existing_account = user_load_by_mail($form_state
      ->getValue('name'));
  }

  // Raise an error in case the account already exists locally.
  if ($existing_account) {
    $form_state
      ->setError($form['name'], $this
      ->t('Account @link exists.', [
      '@link' => $existing_account
        ->toLink($existing_account
        ->getAccountName()),
    ]));
  }
}