You are here

public function Populate::preQuery in Views filters populate 8

Run before the view is built.

This gives all the handlers some time to set up before any handler has been fully run.

Overrides HandlerBase::preQuery

File

src/Plugin/views/filter/Populate.php, line 151

Class

Populate
Filter handler which allows to search on multiple fields.

Namespace

Drupal\views_filters_populate\Plugin\views\filter

Code

public function preQuery() {

  // start with default value
  $value = $this->value;

  // If exposed, take data from input, as this hasn't reached the views
  // object yet
  if ($this->options['exposed']) {
    $input = $this->view
      ->getExposedInput();
    $identifier = $this->options['expose']['identifier'];
    if (isset($input[$identifier])) {
      $value = $input[$identifier];
    }
  }
  foreach ($this->options['filters'] as $id) {
    $filter = $this->view->filter[$id];
    if (!empty($value)) {
      if ($filter instanceof StringFilter) {
        $filter->value = $value;
      }
      if ($filter instanceof NumericFilter) {
        $filter->value['value'] = $value;
      }
    }
  }
}