public function ExposedFormPluginBase::resetForm in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase::resetForm()
- 9 core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase::resetForm()
Resets all the states of the exposed form.
This method is called when the "Reset" button is triggered. Clears user inputs, stored session, and the form state.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
1 call to ExposedFormPluginBase::resetForm()
- ExposedFormPluginBase::exposedFormSubmit in core/modules/ views/ src/ Plugin/ views/ exposed_form/ ExposedFormPluginBase.php 
- Submits the exposed form.
File
- core/modules/ views/ src/ Plugin/ views/ exposed_form/ ExposedFormPluginBase.php, line 330 
Class
- ExposedFormPluginBase
- Base class for Views exposed filter form plugins.
Namespace
Drupal\views\Plugin\views\exposed_formCode
public function resetForm(&$form, FormStateInterface $form_state) {
  // _SESSION is not defined for users who are not logged in.
  // If filters are not overridden, store the 'remember' settings on the
  // default display. If they are, store them on this display. This way,
  // multiple displays in the same view can share the same filters and
  // remember settings.
  $display_id = $this->view->display_handler
    ->isDefaulted('filters') ? 'default' : $this->view->current_display;
  $session = $this->view
    ->getRequest()
    ->getSession();
  $views_session = $session
    ->get('views', []);
  if (isset($views_session[$this->view->storage
    ->id()][$display_id])) {
    unset($views_session[$this->view->storage
      ->id()][$display_id]);
  }
  $session
    ->set('views', $views_session);
  // Set the form to allow redirect.
  if (empty($this->view->live_preview) && !\Drupal::request()
    ->isXmlHttpRequest()) {
    $form_state
      ->disableRedirect(FALSE);
  }
  else {
    $form_state
      ->setRebuild();
    $this->view->exposed_data = [];
  }
  $form_state
    ->setRedirect('<current>');
  $form_state
    ->setValues([]);
}