You are here

protected function Name::valueForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/user/src/Plugin/views/filter/Name.php \Drupal\user\Plugin\views\filter\Name::valueForm()

Options form subform for setting options.

This should be overridden by all child classes and it must define $form['value']

Overrides InOperator::valueForm

See also

buildOptionsForm()

File

core/modules/user/src/Plugin/views/filter/Name.php, line 21

Class

Name
Filter handler for usernames.

Namespace

Drupal\user\Plugin\views\filter

Code

protected function valueForm(&$form, FormStateInterface $form_state) {
  $users = $this->value ? User::loadMultiple($this->value) : [];
  $default_value = EntityAutocomplete::getEntityLabels($users);
  $form['value'] = [
    '#type' => 'entity_autocomplete',
    '#title' => $this
      ->t('Usernames'),
    '#description' => $this
      ->t('Enter a comma separated list of user names.'),
    '#target_type' => 'user',
    '#tags' => TRUE,
    '#default_value' => $default_value,
    '#process_default_value' => $this
      ->isExposed(),
  ];
  $user_input = $form_state
    ->getUserInput();
  if ($form_state
    ->get('exposed') && !isset($user_input[$this->options['expose']['identifier']])) {
    $user_input[$this->options['expose']['identifier']] = $default_value;
    $form_state
      ->setUserInput($user_input);
  }
}