You are here

public function MailgunAdminSettingsForm::validateForm in Mailgun 8

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/MailgunAdminSettingsForm.php, line 62

Class

MailgunAdminSettingsForm
Provides Mailgun configuration form.

Namespace

Drupal\mailgun\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $entered_api_key = $form_state
    ->getValue('api_key');
  if (!empty($entered_api_key) && $this->mailgunHandler
    ->validateMailgunApiKey($entered_api_key) === FALSE) {
    $form_state
      ->setErrorByName('api_key', $this
      ->t("Couldn't connect to the Mailgun API. Please check your API settings."));
  }
}