You are here

public function MailingListImportForm::buildForm in Mailing List 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/MailingListImportForm.php, line 79

Class

MailingListImportForm
Mailing list import.

Namespace

Drupal\mailing_list\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, MailingListInterface $mailing_list = NULL) {
  $this->mailingList = $mailing_list;
  $form['#title'] = $this
    ->t('Import subscriptions into %label mailing list', [
    '%label' => $mailing_list
      ->label(),
  ]);
  $form['emails'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Email addresses'),
    '#description' => $this
      ->t('The email addresses to subscribe, one per line.'),
    '#required' => TRUE,
    '#rows' => 10,
    '#resizable' => 'vertical',
    '#default_value' => '',
  ];
  $form['no_duplicate'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Prevent duplicates'),
    '#description' => $this
      ->t('Do not create new subscriptions for already existent subscribed emails'),
    '#default_value' => TRUE,
  ];
  $form['activate'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Create as active'),
    '#description' => $this
      ->t('Set active status for new subscriptions.'),
    '#default_value' => TRUE,
  ];
  $form['activate_existent'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Active existent'),
    '#description' => $this
      ->t('Enable to activate existing inactive subscriptions.'),
    '#default_value' => FALSE,
    '#states' => [
      'disabled' => [
        ':input[name="activate"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
  ];
  $form['anonymous'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Anonymous subscriber'),
    '#description' => $this
      ->t('New subscriptions will be owned by the anonymous user. Existing subscriptions will not be altered.'),
    '#default_value' => TRUE,
  ];
  $form['actions']['import'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Import'),
  ];
  return $form;
}