You are here

protected function Populate::valueForm in Views filters populate 8

Provide a simple textfield for equality

Overrides FilterPluginBase::valueForm

See also

\Drupal\views\Plugin\views\filter\StringFilter;

File

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

Class

Populate
Filter handler which allows to search on multiple fields.

Namespace

Drupal\views_filters_populate\Plugin\views\filter

Code

protected function valueForm(&$form, FormStateInterface $form_state) {
  if ($exposed = $form_state
    ->get('exposed')) {
    $identifier = $this->options['expose']['identifier'];
  }
  $form['value'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Value'),
    '#size' => 30,
    '#default_value' => $this->value,
  ];
  if (!empty($this->options['expose']['placeholder'])) {
    $form['value']['#attributes']['placeholder'] = $this->options['expose']['placeholder'];
  }
  $user_input = $form_state
    ->getUserInput();
  if ($exposed && !isset($user_input[$identifier])) {
    $user_input[$identifier] = $this->value;
    $form_state
      ->setUserInput($user_input);
  }
  if (!isset($form['value'])) {

    // Ensure there is something in the 'value'.
    $form['value'] = [
      '#type' => 'value',
      '#value' => NULL,
    ];
  }
}