You are here

public function MailgunTestEmailForm::buildForm in Mailgun 8

Form constructor.

Parameters

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

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

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/MailgunTestEmailForm.php, line 90

Class

MailgunTestEmailForm
Provides test email form with common email parameters.

Namespace

Drupal\mailgun\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $this->mailgunHandler
    ->moduleStatus(TRUE);

  // Display a warning if Mailgun is not a default mailer.
  $sender = $this
    ->config('mailsystem.settings')
    ->get('defaults.sender');
  if (!strstr($sender, 'mailgun_')) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('Mailgun is not a default Mailsystem plugin. You may update settings at @link.', [
      '@link' => Link::createFromRoute($this
        ->t('here'), 'mailsystem.settings')
        ->toString(),
    ]), 'warning');
  }

  // We can test all mail systems with this form.
  $form['to'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('To'),
    '#required' => TRUE,
    '#description' => $this
      ->t('Email will be sent to this address. You can use commas to separate multiple recipients.'),
    '#default_value' => $this->user
      ->getEmail(),
  ];
  $form['body'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Message'),
    '#required' => TRUE,
    '#default_value' => $this
      ->t('Howdy!

If this e-mail is displayed correctly and delivered sound and safe, congrats! You have successfully configured Mailgun.'),
  ];
  $form['include_attachment'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Include attachment'),
    '#description' => $this
      ->t('If checked, an image will be included as an attachment with the test e-mail.'),
  ];
  $form['extra'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Additional parameters'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => $this
      ->t('You may test more parameters to make sure they are working.'),
  ];
  $form['extra']['reply_to'] = [
    '#type' => 'email',
    '#title' => $this
      ->t('Reply-To'),
  ];
  $form['extra']['cc'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('CC'),
    '#description' => $this
      ->t('You can use commas to separate multiple recipients.'),
  ];
  $form['extra']['bcc'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('BCC'),
    '#description' => $this
      ->t('You can use commas to separate multiple recipients.'),
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Send'),
  ];
  $form['actions']['cancel'] = [
    '#type' => 'link',
    '#title' => $this
      ->t('Cancel'),
    '#url' => Url::fromRoute('mailgun.admin_settings_form'),
  ];
  return $form;
}