I want to attach managers to site customers. I made Entity Reference "user-to-user" and now I want to select users only with role "Managers".
How can I make such filter?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityAs far I understood you want to see only "Managers" in Entity Reference widget on user add/edit page.
Entity reference widget can filter values by using "Views" module.
You can just create an "Entity reference view" and get all users with role "Manager" there.
Here is instruction for widget settings: https://drupal.stackexchange.com/a/38917/6309
Its Good To simple Alter you form, update the field options, Drupal did not provide a simple way to select a user by a role in the entity reference
feedback_form_events_node_form_alter(&$form, $form_state, $form_id) {
if($form_id== 'events_node_form'){
$form['event'] = array(
'#type' => 'select',
'#title' => t('Select Event'),
'#options' => $event,
'#required' => TRUE,
'#prefix' => ' <li class="custom-select">',
'#suffix' => '</li>',
);
}
}