You are here

function Name::value_form in Views (for Drupal 7) 8.3

Options form subform for setting options.

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

Overrides InOperator::value_form

See also

buildOptionsForm()

File

lib/Views/user/Plugin/views/filter/Name.php, line 27
Definition of Views\user\Plugin\views\filter\Name.

Class

Name
Filter handler for usernames.

Namespace

Views\user\Plugin\views\filter

Code

function value_form(&$form, &$form_state) {
  $values = array();
  if ($this->value) {
    $result = entity_load_multiple_by_properties('user', array(
      'uid' => $this->value,
    ));
    foreach ($result as $account) {
      if ($account->uid) {
        $values[] = $account->name;
      }
      else {
        $values[] = 'Anonymous';

        // Intentionally NOT translated.
      }
    }
  }
  sort($values);
  $default_value = implode(', ', $values);
  $form['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Usernames'),
    '#description' => t('Enter a comma separated list of user names.'),
    '#default_value' => $default_value,
    '#autocomplete_path' => 'admin/views/ajax/autocomplete/user',
  );
  if (!empty($form_state['exposed']) && !isset($form_state['input'][$this->options['expose']['identifier']])) {
    $form_state['input'][$this->options['expose']['identifier']] = $default_value;
  }
}