You are here

public function MailingListsAdminForm::submitForm in Mailgun 8

Form submission 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 FormInterface::submitForm

File

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

Class

MailingListsAdminForm
Provides admin form for Mailgun lists management.

Namespace

Drupal\mailgun_mailing_lists\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $name = $form_state
    ->getValue('list_name');
  $address = $form_state
    ->getValue('list_address');
  $description = $form_state
    ->getValue('description');
  $description = $description ? $description : $name;
  try {
    $this->mailgunClient
      ->mailingList()
      ->create($address, $name, $description, $form_state
      ->getValue('access_level'));
    $this
      ->messenger()
      ->addMessage($this
      ->t('The list %name has been successfully created.', [
      '%name' => $name,
    ]));
  } catch (HttpClientException $e) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('The list could not be created: @message.', [
      '@message' => $e
        ->getMessage(),
    ]), 'error');
  }
}