How to change a Textfield into a Select list in a Views Exposed Filter Figured this question would be asked before, but don't see it.
I have a views exposed filter with a Text Field as one of the filters. I'd like to display this filter as a Select List instead of the standard text input or autocomplete.
Any advice on how to?
Okay, figured out a solid solution using hook_form_alter.
function MODULENAME_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
    
    if ($form['#id'] == 'EXPOSED-FORM-ID') {
    
        $nids = \Drupal::entityQuery('node')-&gt;condition('type','CONTENTTYPE')-&gt;execute();
        $nodes = \Drupal\node\Entity\Node::loadMultiple($nids);
        $options = ['' =&gt; 'All'];
    
        foreach($nodes as $nid =&gt; $node) {
          $value = $node-&gt;get('FIELD_NAME')-&gt;getString();
    
          if (isset($value)) {
            $options[$value] = $value;
          }
        }
    
        if (isset($form['FIELD_NAME_value'])) {
          $form['FIELD_NAME_value']['#type'] = 'select';
          $form['FIELD_NAME_value']['#options'] = $options;
          $form['FIELD_NAME_value']['#size'] = 1;
        }
      }
    }
    
}