You are here

public function MassContactMessageConfirmForm::buildForm in Mass Contact 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 ConfirmFormBase::buildForm

File

src/Form/MassContactMessageConfirmForm.php, line 129

Class

MassContactMessageConfirmForm
Form object for the Mass Contact Confirm form.

Namespace

Drupal\mass_contact\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Build a summary of chosen settings for sending the message.
  // Category list.
  $categories = [];

  // Categories selected, if any.
  $cids = $this->massContactMessage
    ->getCategories();
  if (!empty($cids)) {
    $items = [];
    foreach ($cids as $cid) {
      $items[] = $cid
        ->label();
    }
    sort($items);
    $categories = [
      '#type' => 'ul',
      '#title' => $this
        ->t('Categories'),
      '#items' => $items,
      '#theme' => 'item_list',
    ];
  }

  // Only admins can override optout settings.
  $optout = [];
  if ($this
    ->currentUser()
    ->hasPermission('mass contact administer')) {

    // 'Optout' settings.
    if ($this->messageConfigs['respect_opt_out']) {
      $optout_message = $this
        ->t('You have selected to respect user opt-outs. If a user has opted out of emails they will not receive this mass contact message.');
    }
    else {
      $optout_message = $this
        ->t('You have selected to @not respect user opt-outs. Emails will be sent to all users even if they have elected not to receive a mass contact message.', [
        '@not' => 'NOT',
      ]);
    }
    $optout = [
      '#type' => 'ul',
      '#title' => $this
        ->t('Respect user opt-outs'),
      '#items' => [
        $optout_message,
      ],
      '#theme' => 'item_list',
    ];
  }
  $bcc = [];

  // Check if the user is allowed to override the BCC setting.
  if ($this
    ->currentUser()
    ->hasPermission('mass contact override bcc')) {

    // 'Send as BCC' settings.
    if ($this->messageConfigs['use_bcc']) {
      $bcc_message = $this
        ->t("Recipients of this message will be HIDDEN on the email.");
    }
    else {
      $bcc_message = $this
        ->t("Recipients of this message will @not be HIDDEN on the email.", [
        '@not' => 'NOT',
      ]);
    }
    $bcc = [
      '#type' => 'ul',
      '#title' => $this
        ->t('Send as BCC (hide recipients)'),
      '#items' => [
        $bcc_message,
      ],
      '#theme' => 'item_list',
    ];
  }

  // 'Send me a copy' settings.
  if ($this->messageConfigs['send_me_copy_user']) {
    $copy_message = $this
      ->t("A copy of this message will be sent to you.");
  }
  else {
    $copy_message = $this
      ->t("A copy of this message will @not be sent to you.", [
      '@not' => 'NOT',
    ]);
  }
  $copy = [
    '#type' => 'ul',
    '#title' => $this
      ->t('Send yourself a copy'),
    '#items' => [
      $copy_message,
    ],
    '#theme' => 'item_list',
  ];
  $archive = [];

  // Check if the user is allowed to override the node copy setting.
  if ($this
    ->currentUser()
    ->hasPermission('mass contact override archiving')) {

    // 'Archive a copy of this message' settings.
    if ($this->messageConfigs['create_archive_copy']) {
      $archive_message = $this
        ->t("A copy of this message will be archived on this site.");
    }
    else {
      $archive_message = $this
        ->t("A copy of this message will @not be archived on this site.", [
        '@not' => 'NOT',
      ]);
    }
    $archive = [
      '#type' => 'ul',
      '#title' => $this
        ->t('Archive a copy of this message on this website'),
      '#items' => [
        $archive_message,
      ],
      '#theme' => 'item_list',
    ];
  }

  // Summary of all selections.
  $form['settings_summary'] = [
    '#theme' => 'item_list',
    '#type' => 'ol',
    '#title' => $this
      ->t('You selected the following settings:'),
    '#prefix' => '<div id="settings-summary">',
    '#suffix' => '</div>',
    '#items' => [
      $categories,
      $optout,
      $bcc,
      $copy,
      $archive,
    ],
  ];
  return $form + parent::buildForm($form, $form_state);
}