You are here

public function FilterPluginBase::buildExposedForm in Views (for Drupal 7) 8.3

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

lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php, line 753
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
      ->operator_form($form, $form_state);
    $form[$operator] = $form['operator'];
    if (isset($form[$operator]['#title'])) {
      unset($form[$operator]['#title']);
    }
    $this
      ->exposed_translate($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
      ->value_form($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
      ->exposed_translate($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']);
    }
  }
}