I have a view which has a filter by users that created de nodes. This filter is exposed, in order to select an user and filter the results by this user. I would like to change the default autocomplete filter by a select list of user, and in this list I want to show only some users.
I followed this tutorial but without success. Although I change "uid" form field, It does anything.
How could I do it? Thanks
UPDATE: my code.
function my_module_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$pos = stripos($form['#id'], 'views-exposed-form-my-form');
if ($pos !== false) {
$opcusuarios = array();
$query = \Drupal::entityQuery('user');
... some conditions ...
$entity_ids = $query->execute();
$usuarios = \Drupal::entityTypeManager()->getStorage('user')->loadMultiple($entity_ids);
foreach($usuarios as $user) {
$opcusuarios[$user->id()] = $user->getAccountName();
}
// Change the input
$form['uid']['#type'] = 'select';
$form['uid']['#multiple'] = FALSE;
// Add the $options from above to our select list
$form['uid']['#options'] = $opcusuarios;
unset($form['uid']['#size']);
}
}