You are here

public function DeleteMultiple::buildForm in Message 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/DeleteMultiple.php, line 85

Class

DeleteMultiple
Provides a message deletion confirmation form.

Namespace

Drupal\message\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $this->messages = $this->tempStoreFactory
    ->get('message_multiple_delete_confirm')
    ->get(\Drupal::currentUser()
    ->id());
  if (empty($this->messages)) {
    return new RedirectResponse($this
      ->getCancelUrl()
      ->setAbsolute()
      ->toString());
  }
  $form['messages'] = [
    '#theme' => 'item_list',
    '#items' => array_map(function (Message $message) {
      $params = [
        '@id' => $message
          ->id(),
        '@template' => $message
          ->getTemplate()
          ->label(),
      ];
      return t('Delete message ID @id for template @template', $params);
    }, $this->messages),
  ];
  $form = parent::buildForm($form, $form_state);
  $form['actions']['cancel']['#href'] = $this
    ->getCancelRoute();
  $form['actions']['submit']['#submit'] = [
    '::submitForm',
  ];
  return $form;
}