You are here

public function SetupForm::validateForm in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 src/Form/SetupForm.php \Drupal\acquia_connector\Form\SetupForm::validateForm()
  2. 3.x src/Form/SetupForm.php \Drupal\acquia_connector\Form\SetupForm::validateForm()

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormBase::validateForm

File

src/Form/SetupForm.php, line 159

Class

SetupForm
Acquia Connector setup form.

Namespace

Drupal\acquia_connector\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $storage = $form_state
    ->getStorage();
  if (!isset($storage['choose'])) {
    try {
      $response = $this->client
        ->getSubscriptionCredentials($form_state
        ->getValue('email'), $form_state
        ->getValue('pass'));
    } catch (ConnectorException $e) {

      // Set form error to prevent switching to the next page.
      if ($e
        ->isCustomized()) {
        $form_state
          ->setErrorByName('', $e
          ->getCustomMessage());
      }
      else {
        $this
          ->getLogger('acquia connector')
          ->error($e
          ->getMessage());
        $form_state
          ->setErrorByName('', $this
          ->t("Can't connect to the Acquia Subscription."));
      }
    }
    if (!empty($response)) {
      $storage['response'] = $response;
    }
  }
  $form_state
    ->setStorage($storage);
}