You are here

public function SubscriberMassSubscribeForm::buildForm in Simplenews 8

Same name and namespace in other branches
  1. 8.2 src/Form/SubscriberMassSubscribeForm.php \Drupal\simplenews\Form\SubscriberMassSubscribeForm::buildForm()
  2. 3.x src/Form/SubscriberMassSubscribeForm.php \Drupal\simplenews\Form\SubscriberMassSubscribeForm::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/SubscriberMassSubscribeForm.php, line 52

Class

SubscriberMassSubscribeForm
Do a mass subscription for a list of email addresses.

Namespace

Drupal\simplenews\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['emails'] = array(
    '#type' => 'textarea',
    '#title' => t('Email addresses'),
    '#cols' => 60,
    '#rows' => 5,
    '#description' => t('Email addresses must be separated by comma, space or newline.'),
  );
  $form['newsletters'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Subscribe to'),
    '#options' => simplenews_newsletter_list(),
    '#required' => TRUE,
  );
  foreach (simplenews_newsletter_get_all() as $id => $newsletter) {
    $form['newsletters'][$id]['#description'] = Html::escape($newsletter->description);
  }
  $form['resubscribe'] = array(
    '#type' => 'checkbox',
    '#title' => t('Force resubscription'),
    '#description' => t('If checked, previously unsubscribed e-mail addresses will be resubscribed. Consider that this might be against the will of your users.'),
  );

  // Include language selection when the site is multilingual.
  // Default value is the empty string which will result in receiving emails
  // in the site's default language.
  if ($this->languageManager
    ->isMultilingual()) {
    $options[''] = t('Site default language');
    $languages = $this->languageManager
      ->getLanguages();
    foreach ($languages as $langcode => $language) {
      $options[$langcode] = $language
        ->getName();
    }
    $form['language'] = array(
      '#type' => 'radios',
      '#title' => t('Anonymous user preferred language'),
      '#default_value' => '',
      '#options' => $options,
      '#description' => t('New subscriptions will be subscribed with the selected preferred language. The language of existing subscribers is unchanged.'),
    );
  }
  else {
    $form['language'] = array(
      '#type' => 'value',
      '#value' => '',
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Subscribe'),
  );
  return $form;
}