1

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?

2 Answers 2

6

As 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

0

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>',
);
  }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.