You are here

public function DeleteMultiple::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/DeleteMultiple.php, line 137

Class

DeleteMultiple
Provides a message deletion confirmation form.

Namespace

Drupal\message_ui\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Get the message IDs.
  $query = \Drupal::entityQuery('message');
  $result = $query
    ->condition('type', $form_state['values']['types'], 'IN')
    ->execute();
  if (empty($result['message'])) {

    // No messages found, return.
    $this
      ->messenger()
      ->addError(t('No messages were found according to the parameters you entered'));
    return;
  }

  // Prepare the message IDs chunk array for batch operation.
  $chunks = array_chunk(array_keys($result['message']), 100);
  $operations = [];

  // @todo : update the operation below to new structure.
  foreach ($chunks as $chunk) {
    $operations[] = [
      'message_delete_multiple',
      [
        $chunk,
      ],
    ];
  }

  // Set the batch.
  $batch = [
    'operations' => $operations,
    'title' => t('deleting messages.'),
    'init_message' => t('Starting to delete messages.'),
    'progress_message' => t('Processed @current out of @total.'),
    'error_message' => t('The batch operation has failed.'),
  ];
  batch_set($batch);
  batch_process($_GET['q']);
}