You are here

public function NewsletterSettingsForm::buildForm in Simplenews 8

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

File

src/Form/NewsletterSettingsForm.php, line 30

Class

NewsletterSettingsForm
Configure simplenews newsletter settings.

Namespace

Drupal\simplenews\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('simplenews.settings');
  $form['simplenews_default_options'] = array(
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Default newsletter options'),
    '#collapsible' => FALSE,
    '#description' => $this
      ->t('These options will be the defaults for new newsletters, but can be overridden in the newsletter editing form.'),
  );
  $links = array(
    ':mime_mail_url' => 'http://drupal.org/project/mimemail',
    ':html_url' => 'http://drupal.org/project/htmlmail',
  );
  $description = $this
    ->t('Default newsletter format. Install <a href=":mime_mail_url">Mime Mail</a> module or <a href=":html_url">HTML Mail</a> module to send newsletters in HTML format.', $links);
  $form['simplenews_default_options']['simplenews_format'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Format'),
    '#options' => simplenews_format_options(),
    '#description' => $description,
    '#default_value' => $config
      ->get('newsletter.format'),
  );

  // @todo Do we need these master defaults for 'priority' and 'receipt'?
  $form['simplenews_default_options']['simplenews_priority'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Priority'),
    '#options' => simplenews_get_priority(),
    '#description' => $this
      ->t('Note that email priority is ignored by a lot of email programs.'),
    '#default_value' => $config
      ->get('newsletter.priority'),
  );
  $form['simplenews_default_options']['simplenews_receipt'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Request receipt'),
    '#default_value' => $config
      ->get('newsletter.receipt'),
    '#description' => $this
      ->t('Request a Read Receipt from your newsletters. A lot of email programs ignore these so it is not a definitive indication of how many people have read your newsletter.'),
  );
  $form['simplenews_sender_info'] = array(
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Sender information'),
    '#collapsible' => FALSE,
    '#description' => $this
      ->t('Default sender address that will only be used for confirmation emails. You can specify sender information for each newsletter separately on the newsletter\'s settings page.'),
  );
  $form['simplenews_sender_info']['simplenews_from_name'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('From name'),
    '#size' => 60,
    '#maxlength' => 128,
    '#default_value' => $config
      ->get('newsletter.from_name'),
  );
  $form['simplenews_sender_info']['simplenews_from_address'] = array(
    '#type' => 'email',
    '#title' => $this
      ->t('From email address'),
    '#size' => 60,
    '#maxlength' => 128,
    '#required' => TRUE,
    '#default_value' => $config
      ->get('newsletter.from_address'),
  );
  return parent::buildForm($form, $form_state);
}