You are here

public function CourierMaintenanceForm::submitForm in Courier 2.x

Same name and namespace in other branches
  1. 8 src/Form/CourierMaintenanceForm.php \Drupal\courier\Form\CourierMaintenanceForm::submitForm()

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/CourierMaintenanceForm.php, line 81

Class

CourierMaintenanceForm
Courier maintenance form.

Namespace

Drupal\courier\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $time = \Drupal::time()
    ->getRequestTime() - $form_state
    ->getValue('delete_age');
  $storage = $this->entityTypeManager
    ->getStorage('courier_message_queue_item');
  $ids = $storage
    ->getQuery()
    ->condition('created', $time, '<')
    ->execute();
  $storage
    ->delete($storage
    ->loadMultiple($ids));
  $this
    ->messenger()
    ->addMessage($this
    ->formatPlural(count($ids), '@count message deleted.', '@count messages deleted.'));
}