You are here

public function HtmlMailTestForm::buildForm in HTML Mail 8

Same name and namespace in other branches
  1. 8.3 src/Form/HtmlMailTestForm.php \Drupal\htmlmail\Form\HtmlMailTestForm::buildForm()

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/HtmlMailTestForm.php, line 70

Class

HtmlMailTestForm
Class HtmlMailTestForm.

Namespace

Drupal\htmlmail\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('htmlmail.settings');
  $defaults = $config
    ->get('htmlmail_test');
  if (empty($defaults)) {
    $defaults = [
      'to' => $config
        ->get('site_mail') ?: self::DEFAULT_MAIL,
      'subject' => self::KEY_NAME,
      'body' => [
        'value' => self::KEY_NAME,
      ],
      'class' => HtmlMailHelper::getModuleName(),
    ];
  }
  if (empty($defaults['body']['format'])) {
    $defaults['body']['format'] = filter_default_format();
  }
  $form['to'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('To'),
    '#default_value' => $defaults['to'],
    '#maxlength' => 128,
    '#required' => TRUE,
  ];
  $form['subject'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Subject'),
    '#default_value' => $defaults['subject'],
    '#maxlength' => 128,
    '#required' => TRUE,
  ];
  $form['body'] = [
    '#type' => 'text_format',
    '#title' => $this
      ->t('Body'),
    '#rows' => 20,
    '#default_value' => $defaults['body']['value'],
    '#format' => $defaults['body']['format'],
    '#required' => TRUE,
  ];
  $form['class'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Test mail sending class'),
    '#options' => $this
      ->getOptions(),
    '#default_value' => $defaults['class'],
    '#description' => $this
      ->t('Select the MailSystemInterface implementation to be tested.'),
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Send test message'),
  ];
  return $form;
}