function ExposedFormPluginBase::renderExposedForm

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase::renderExposedForm()
  2. 8.9.x core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase::renderExposedForm()
  3. 10 core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase::renderExposedForm()

Overrides ExposedFormPluginInterface::renderExposedForm

File

core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php, line 111

Class

ExposedFormPluginBase
Base class for Views exposed filter form plugins.

Namespace

Drupal\views\Plugin\views\exposed_form

Code

public function renderExposedForm($block = FALSE) {
    // Deal with any exposed filters we may have, before building.
    $form_state = (new FormState())->setStorage([
        'view' => $this->view,
        'display' => &$this->view->display_handler->display,
        'rerender' => TRUE,
    ])
        ->setMethod('get')
        ->setAlwaysProcess()
        ->disableRedirect();
    // Some types of displays (eg. attachments) may wish to use the exposed
    // filters of their parent displays instead of showing an additional
    // exposed filter form for the attachment as well as that for the parent.
    if (!$this->view->display_handler
        ->displaysExposed() || !$block && $this->view->display_handler
        ->getOption('exposed_block')) {
        $form_state->set('rerender', NULL);
    }
    if (!empty($this->ajax)) {
        $form_state->set('ajax', TRUE);
    }
    $form = \Drupal::formBuilder()->buildForm('\\Drupal\\views\\Form\\ViewsExposedForm', $form_state);
    $errors = $form_state->getErrors();
    // If the exposed form had errors, do not build the view.
    if (!empty($errors)) {
        $this->view->build_info['abort'] = TRUE;
    }
    if (!$this->view->display_handler
        ->displaysExposed() || !$block && $this->view->display_handler
        ->getOption('exposed_block')) {
        return [];
    }
    else {
        return $form;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.