You are here

public function MessageMultipleDeleteForm::submitForm in Message UI 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/MessageMultipleDeleteForm.php, line 95

Class

MessageMultipleDeleteForm
Class MessageMultipleDeleteForm.

Namespace

Drupal\message_ui\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $templates = $form_state
    ->getValue('message_templates');
  $query = $this->entityTypeManager
    ->getStorage('message')
    ->getQuery()
    ->condition('template', $templates, 'IN');

  // Allow other modules to alter the query.
  $this->moduleHandler
    ->alter('message_ui_multiple_message_delete_query', $query);

  // Get the messages.
  $messages = $query
    ->execute();
  $chunks = array_chunk($messages, 250);
  $operations = [];
  foreach ($chunks as $chunk) {
    $operations[] = [
      '\\Drupal\\message_ui\\Form\\MessageMultipleDeleteForm::deleteMessages',
      [
        $chunk,
      ],
    ];
  }

  // Set the batch.
  $batch = [
    'title' => $this
      ->t('Deleting messages'),
    'operations' => $operations,
    'finished' => '\\Drupal\\message_ui\\Form\\MessageMultipleDeleteForm::deleteMessagesFinish',
  ];
  batch_set($batch);
}