You are here

public function MandrillAdminTestForm::buildForm in Mandrill 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 ConfirmFormBase::buildForm

File

src/Form/MandrillAdminTestForm.php, line 57

Class

MandrillAdminTestForm
Form controller for the Mandrill send test email form.

Namespace

Drupal\mandrill\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  $click_tracking_url = Url::fromUri('http://www.drupal.org/project/mandrill');

  // If sending using the mandrill_test_mail service, attachments and bcc are
  // not supported.
  $mandrill_test_mail = \Drupal::config('mailsystem.settings')
    ->get('defaults')['sender'] == 'mandrill_test_mail';
  $form['mandrill_test_address'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Email address to send a test email to'),
    '#default_value' => \Drupal::config('system.site')
      ->get('mail'),
    '#description' => $this
      ->t('Type in an address to have a test email sent there.'),
    '#required' => TRUE,
  );

  // If sending using the mandrill_test_mail service, bcc is not
  // supported so we hide the "Email address to BCC on this test email" text
  // input field.
  if (!$mandrill_test_mail) {
    $form['mandrill_test_bcc_address'] = array(
      '#type' => 'textfield',
      '#title' => $this
        ->t('Email address to BCC on this test email'),
      '#description' => $this
        ->t('Type in an address to have a test email sent there.'),
    );
  }
  $form['mandrill_test_body'] = array(
    '#type' => 'textarea',
    '#title' => $this
      ->t('Test body contents'),
    '#default_value' => $this
      ->t('If you receive this message it means your site is capable of using Mandrill to send email. This url is here to test click tracking: %link', array(
      '%link' => Link::fromTextAndUrl($this
        ->t('link'), $click_tracking_url)
        ->toString(),
    )),
  );

  // If sending using the mandrill_test_mail service, attachments are not
  // supported so we hide the "Include attachment" checkbox.
  if (!$mandrill_test_mail) {
    $form['include_attachment'] = array(
      '#title' => $this
        ->t('Include attachment'),
      '#type' => 'checkbox',
      '#description' => $this
        ->t('If checked, the Drupal icon will be included as an attachment with the test email.'),
      '#default_value' => TRUE,
    );
  }
  return $form;
}