You are here

public function ExposedFormPluginBase::renderExposedForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase::renderExposedForm()

Render the exposed filter form.

This actually does more than that; because it's using FAPI, the form will also assign data to the appropriate handlers for use in building the query.

File

core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php, line 129
Contains \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase.

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);
  if (!$this->view->display_handler
    ->displaysExposed() || !$block && $this->view->display_handler
    ->getOption('exposed_block')) {
    return array();
  }
  else {
    return $form;
  }
}