You are here

public function MailingListsAdminForm::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

modules/mailgun_mailing_lists/src/Form/MailingListsAdminForm.php, line 133

Class

MailingListsAdminForm
Provides admin form for Mailgun lists management.

Namespace

Drupal\mailgun_mailing_lists\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $address = $form_state
    ->getValue('list_address');
  $lists = $this->mailgunClient
    ->mailingList();
  try {
    if ($lists
      ->show($address)) {
      $form_state
        ->setErrorByName('list_address', $this
        ->t('The list %list already exists.', [
        '%list' => $address,
      ]));
    }
  } catch (HttpClientException $e) {
    return;
  }
}