You are here

public function ConfigurationForm::submitFormClear in URLs queuer 8

Submit handler that clears the traffic registry.

Parameters

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

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

File

src/Form/ConfigurationForm.php, line 240

Class

ConfigurationForm
Configuration form for the Url and Path queuer.

Namespace

Drupal\purge_queuer_url\Form

Code

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

  // Clear the traffic registry IF there are no ordinary form errors.
  if (!$form_state
    ->getErrors()) {
    \Drupal::service('purge_queuer_url.registry')
      ->clear();
    $this->messenger
      ->addMessage($this
      ->t("The traffic registry has been cleared, your site needs to get regular traffic before it starts queueing URLs or paths again! Pages currently cached in Drupal's render cache won't be collected unless you clear those, but be careful doing that on a busy site!"));
  }

  // Determine all the AJAX and non-AJAX logic depending on how we're called.
  if ($this
    ->isDialog($form, $form_state)) {
    $response = new AjaxResponse();
    unset($form['#prefix'], $form['#suffix']);
    $form['status_messages'] = [
      '#type' => 'status_messages',
      '#weight' => -10,
    ];
    $response
      ->addCommand(new HtmlCommand('#purgedialogform', $form));
    return $response;
  }
  return parent::submitForm($form, $form_state);
}