public function FilterPluginBase::buildExposedForm

Render our chunk of the exposed filter form when selecting

You can override this if it doesn't do what you expect.

Overrides HandlerBase::buildExposedForm

File

drupal/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php, line 782
Definition of Drupal\views\Plugin\views\filter\FilterPluginBase.

Class

FilterPluginBase
Base class for filters.

Namespace

Drupal\views\Plugin\views\filter

Code

public function buildExposedForm(&$form, &$form_state) {
  if (empty($this->options['exposed'])) {
    return;
  }

  // Build the exposed form, when its based on an operator.
  if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id'])) {
    $operator = $this->options['expose']['operator_id'];
    $this
      ->operatorForm($form, $form_state);
    $form[$operator] = $form['operator'];
    if (isset($form[$operator]['#title'])) {
      unset($form[$operator]['#title']);
    }
    $this
      ->exposedTranslate($form[$operator], 'operator');
    unset($form['operator']);
  }

  // Build the form and set the value based on the identifier.
  if (!empty($this->options['expose']['identifier'])) {
    $value = $this->options['expose']['identifier'];
    $this
      ->valueForm($form, $form_state);
    $form[$value] = $form['value'];
    if (isset($form[$value]['#title']) && !empty($form[$value]['#type']) && $form[$value]['#type'] != 'checkbox') {
      unset($form[$value]['#title']);
    }
    $this
      ->exposedTranslate($form[$value], 'value');
    if (!empty($form['#type']) && ($form['#type'] == 'checkboxes' || $form['#type'] == 'select' && !empty($form['#multiple']))) {
      unset($form[$value]['#default_value']);
    }
    if (!empty($form['#type']) && $form['#type'] == 'select' && empty($form['#multiple'])) {
      $form[$value]['#default_value'] = 'All';
    }
    if ($value != 'value') {
      unset($form['value']);
    }
  }
}