4

I am using an Entity Reference field to refer to users in another content type. The default widgets for the field use the User Name as the label for the dropdown, but I'd like to change that to another field from the user profile entity (ideally combining 'first name' and 'last name' fields). I've looked at Entity Reference Views, but it isn't released and I could not get it to work based on available docs.

  • Did you find the answer? i am searching for a solution for the same problem – Samer Hijazi May 26 '12 at 11:58
  • I'll be out this week, but after that I'll be trying Bojan's solution and will report back. – Andrew Shooner May 27 '12 at 15:38
4

Entityrefence 7.x-1.x-dev allows you to use results from a View in the select box, which will allow you to do what you need.

  • create/edit a view, add a new display of type "Entity Reference" to it, setting properly the fields you want to be shown;
  • edit the entityreference field, find "entity selection mode", set it to "views: filter by an entity reference view" then select the proper "view used to select the entities" option created on previous step.
  • This sounded like it might work, and the current dev version of entityreference indeed does have a "Entity Reference" display type exposed in views, but the functionality unfortunately seems broken at the moment. Adding a display of this type creates an empty screen. – JamesWilson Aug 3 '12 at 20:10
  • This works with Views 7.x-3.5 and Entity Reference 7.x-1.0. – mpdonadio Dec 13 '12 at 15:54
1

It has taken me a while to understand how to build this Entity Reference within D7. If it helps anyone, I will describe how I think it can be built here.

In my case, I am creating a Project (node entity) and relating it to a Primary Investigator PI (profile2 entity). It is a 2-way relationship, but we will be adding PI to the Project (instead of adding a Project to the Profile, at least initially). So, Project content type will contain an Entity Reference to Profile.

The least confusing way, in my opinion, is to create the view for the entity first. Add an Entity Reference display to any existing or new view (any best practice advice here?). The Format should be Entity Reference List and show Inline fields. The Filter criteria should list the type of Entity you are referring to - in my case Profile. Add more Fields that you would want to appear for the user to select from - in my case Last Name and First Name. Then go back to the Settings for Entity Reference List and add those items to the Search fields list. If desired, set up Sort Criteria for your list, which should now show up in your Preview. Save this View.

In the Project content type, add a new field referring to the PI profile [label: prof_ref_pi, field type: Entity Reference, Widget: Select list (have not been able to get Autocomplete to work as of yet)] and Save. Target type in my case is Profile. Choose Mode: Views: Filter by an entity reference view (I could not figure out how to get the Simple filter to show field values but Views does work). Select the Entity Reference display in the View you created earlier, and Save. Save your Content Type.

Go to Content and create/edit a piece of content - in my case, Project. The reference field there should have a drop-down with the View information you specified.

To use in a View, for example to show a Project and its PI, choose to create the view on a Content of Projects using Fields and add the Relationship Entity Reference - in my case, project_ref_pi. Then, in Fields, choose from the Projects fields and those items from the Profile fields using the relationship.

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.