Alter views contextual filter field I have two content types, Brand and Sector. Brand have a sector field which is an Entity reference field.

I have views that display the list of Brands and it has a sector contextual filter which displayed as an input field where you have to input a node ID.

I was trying to make it a dropdown with sector titles for a user friendly experience but wasn't able to achieve this in views. So I decided to alter the views form but it seems like that it's not working the same as in D7.

What's the right way to alter the views field or is there a way to render a field as dropdown using views?
OK, I managed to achieve this by implementing hook_form_FORM_ID_alter() in my mytheme.theme file.

/**
 * Implements hook_form_FORM_ID_alter().
 */
function mytheme_form_views_exposed_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  if ($form['#id'] == 'my-views-exposed-form-id') {
    $query = db_select('node_field_data', 'n')
      -&gt;fields('n', array('nid', 'title'))
      -&gt;condition('type', 'sector')
      -&gt;condition('status', 1)
      -&gt;orderBy('title', 'ASC');
    $options = $query-&gt;execute()-&gt;fetchAllKeyed();

    // $form['sector'] is a type text, changing it to select.
    $form['sector'] = array(
      '#type' =&gt; 'select',
      '#options' =&gt; array('' =&gt; t('Filter by Sector')-&gt;render()) + $options
    );
  }
}


Hope it will help someone.