/**
  * {@inheritdoc}
  */
 protected function valueForm(&$form, FormStateInterface $form_state)
 {
     parent::valueForm($form, $form_state);
     // Set autocompletion.
     $path = $this->isMultiValued() ? 'admin/views/ajax/autocomplete/user' : 'user/autocomplete';
     $form['value']['#autocomplete_path'] = $path;
 }
 /**
  * {@inheritdoc}
  */
 protected function valueForm(&$form, FormStateInterface $form_state)
 {
     parent::valueForm($form, $form_state);
     if (!empty($this->definition['vocabulary'])) {
         $vocabulary = Vocabulary::load($this->definition['vocabulary']);
         $title = $this->t('Select terms from vocabulary @voc', array('@voc' => $vocabulary->label()));
     } else {
         $vocabulary = FALSE;
         $title = $this->t('Select terms');
     }
     $form['value']['#title'] = $title;
     if ($vocabulary && $this->options['type'] == 'textfield') {
         $form['value']['#autocomplete_path'] = 'admin/views/ajax/autocomplete/taxonomy/' . $vocabulary->id();
     } else {
         if ($vocabulary && !empty($this->options['hierarchy'])) {
             /** @var \Drupal\taxonomy\TermStorageInterface $term_storage */
             $term_storage = \Drupal::entityManager()->getStorage('taxonomy_term');
             $tree = $term_storage->loadTree($vocabulary->id());
             $options = array();
             if ($tree) {
                 foreach ($tree as $term) {
                     $choice = new \stdClass();
                     $choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name);
                     $options[] = $choice;
                 }
             }
         } else {
             $options = array();
             $query = db_select('taxonomy_term_data', 'td');
             $query->innerJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
             $query->fields('td');
             $query->orderby('tv.weight');
             $query->orderby('tv.name');
             $query->orderby('td.weight');
             $query->orderby('td.name');
             $query->addTag('term_access');
             if ($vocabulary) {
                 $query->condition('tv.vid', $vocabulary->id());
             }
             $result = $query->execute();
             foreach ($result as $term) {
                 $options[$term->tid] = $term->name;
             }
         }
         $default_value = (array) $this->value;
         if ($form_state->get('exposed')) {
             $identifier = $this->options['expose']['identifier'];
             if (!empty($this->options['expose']['reduce'])) {
                 $options = $this->reduceValueOptions($options);
                 if (!empty($this->options['expose']['multiple']) && empty($this->options['expose']['required'])) {
                     $default_value = array();
                 }
             }
             if (empty($this->options['expose']['multiple'])) {
                 if (empty($this->options['expose']['required']) && (empty($default_value) || !empty($this->options['expose']['reduce']))) {
                     $default_value = 'All';
                 } elseif (empty($default_value)) {
                     $keys = array_keys($options);
                     $default_value = array_shift($keys);
                 } elseif ($default_value == array('')) {
                     $default_value = 'All';
                 } else {
                     $copy = $default_value;
                     $default_value = array_shift($copy);
                 }
             }
         }
         $form['value']['#type'] = 'select';
         $form['value']['#multiple'] = TRUE;
         $form['value']['#options'] = $options;
         $form['value']['#size'] = min(9, count($options));
         $form['value']['#default_value'] = $default_value;
         $input =& $form_state->getUserInput();
         if ($form_state->get('exposed') && isset($identifier) && !isset($input[$identifier])) {
             $input[$identifier] = $default_value;
         }
     }
 }