I have added some custom fields to my D8 site's user profiles. Would it be possible to add users to a entity reference field on a node using one of these? For example phone number, as that is one of the fields. Or am I stuck referring to only the users username?

  • What is the ultimate goal? Are you trying to display fields of the author on the node? Or are you trying to show fields of any user selected within a field on the node? Or do you mean, use an entity reference field to select a user, but instead of the user it just pops in the phone number field in one of the fields of the node? Also is this 7 or 8? – Matt Apr 11 '17 at 18:05
  • The nodes are "groups", where the added users would be listed as participants. Also, if I can manage, the added users will have edit-permission on the node in question. So, adding users by phone number (or email f.ex.) would be simpler for less "techy" users than the drupal username. If more information is needed, please advise. – Lars Rødal Apr 11 '17 at 18:14
  • So on each node you can add as many users as you want to it? So if your node content type was 'Team' and the team is composed of an unlimited 'user' reference field. And when you visit the team page, you want to display the list of users added to that team, and their phone numbers. Is that correct? – Matt Apr 11 '17 at 18:16
  • Yes, you can add as many users as wanted. No, I would like the ability to add the users to the field using f.ex. phone number or email - instead of using the user name (which is the normal behaviour). On the node I have them displayed using user name right now, but I would like to show the full name if available. Here is an example node: cc-moon.net/groups/integrated-market-dynamics-and-logistics The bottom members in the right side list are drupal user accounts. :) – Lars Rødal Apr 11 '17 at 18:21
  • 1
    Also do you need it to autocomplete or would you be okay with just entering the phone numbers and letting it match up afterwards? – Matt Apr 11 '17 at 18:26

You can use any field to lookup a user in a entity reference field. You just need 2 things: an entity reference View & a configured entity reference field.

  1. Through the Views UI, you can add a User view with an Entity Reference Display. Add any fields to the View that you'll want to search on. Once your do, the Settings link next to Format:Entity Reference list will popup a modal that will let select your Search Fields.

  2. After you've created your view, add your node's entity reference field. Set the Reference method to Views: Filter by an entity reference view. Where View used to select the entities is set to the view you created in step #1. Once the new field config is saved, you'll be able to search for any users based of the text values in the fields selected in Search Fields.

| improve this answer | |
  • Thanks for the tip! This worked like a charm! I only have one follow-up question: I can now search for those fields, but only the user name is shown for auto-complete. Is there any way I could show the user name and email, f.ex.? – Lars Rødal Jun 16 '17 at 12:53

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.