public function SubscriberMassSubscribeForm::buildForm in Simplenews 8.2
Same name and namespace in other branches
- 8 src/Form/SubscriberMassSubscribeForm.php \Drupal\simplenews\Form\SubscriberMassSubscribeForm::buildForm()
- 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 78
Class
- SubscriberMassSubscribeForm
- Do a mass subscription for a list of email addresses.
Namespace
Drupal\simplenews\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['emails'] = [
'#type' => 'textarea',
'#title' => $this
->t('Email addresses'),
'#cols' => 60,
'#rows' => 5,
'#description' => $this
->t('Email addresses must be separated by comma, space or newline.'),
];
$form['newsletters'] = [
'#type' => 'checkboxes',
'#title' => $this
->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'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Force resubscription'),
'#description' => $this
->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[''] = $this
->t('Site default language');
$languages = $this->languageManager
->getLanguages();
foreach ($languages as $langcode => $language) {
$options[$langcode] = $language
->getName();
}
$form['language'] = [
'#type' => 'radios',
'#title' => $this
->t('Anonymous user preferred language'),
'#default_value' => '',
'#options' => $options,
'#description' => $this
->t('New subscriptions will be subscribed with the selected preferred language. The language of existing subscribers is unchanged.'),
];
}
else {
$form['language'] = [
'#type' => 'value',
'#value' => '',
];
}
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Subscribe'),
];
return $form;
}