How to Use Entity Reference Views in Drupal 7

How to Use Entity Reference Views in Drupal 7

Entity Reference Views are one way you can make life easier for Drupal content creators.

Normally, when people are creating content on your site, each field consists of a single box with a single data point. For example, in a list of people, you might get only the person’s name.

Entity Reference Views allows you to provide far more information. For example, you can add photos and personal details to your list of people.


Entity Reference Views in Drupal 7

In this example, I have a content type called “Presentations” and another content type called “Speakers”. Every time I add a presentation, I want to choose from a list of speakers.

  • Install and enable Views and Entity Reference.
  • Go to Structure > Views > Add new view.
  • Create a view of the content that you want content editors to choose from. In this example, I’m going to make a list of “Speakers”:
Create a view of content in Drupal
  • At the top of the page, click “Add” then “Entity Reference”:
Adding an entity reference view
  • Click “Settings” next to “Entity Reference list”.
Click
  • Search fields: Choose the field you want users to search by.
  • Click “Apply (this display)”.
Choose the field you want users to search by in Views
  • Check the preview to make sure your view is working …
The preview of our entity reference view

Step #2. Add a Field with the Entity Reference View

  • Go to Structure > Content types.
  • Add an “Entity Reference” field.
Add an Entity Reference field
  • Target type: Choose to link to nodes, users, files or whatever else you want to display.
  • Mode: Choose “View: Filter by an entity reference view.”
  • View used to select the entities: choose the view you created.
  • Click “Save field settings”.
Settings for an Entity Reference field
  • Click “Add content” and the data entry for your field will use the View you created:
A working Entity Reference field

Entity Reference Views Widget

It’s possible to extend this module by using Entity Reference View Widget. This places your view inside a pop-up box to make it easier to select items.

There’s a tutorial here and this video has guidance:


Entity Reference Views in Drupal 8

Both Views and Entity Reference are now part of the Drupal 8 core. To use Entity Reference Views in Drupal 8, the process is like this:

  • Create a view, as we showed above.
  • Go to Structure > Content types > Add field.
Adding an Entity Reference field in Drupal 8

Click through the settings and under “Reference type”, you can choose “Views: Filter by an entity reference view”.

The setting Views: Filter by an entity reference view

Author

  • Steve Burge

    Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.

0 0 votes
Article Rating
Subscribe
Notify of
6 Comments
Oldest
Newest
Inline Feedbacks
View all comments
shawnmmatthews
shawnmmatthews
6 years ago

Please note this is currently broken in 8.0+ [url=https://www.drupal.org/node/2174633]https://www.drupal.org/node…[/url]

danielpickering
6 years ago
Reply to  shawnmmatthews

Thanks for sharing.

Robert Powell
Robert Powell
6 years ago
Reply to  shawnmmatthews

kudos, this helped a lot.

maikr
5 years ago
Reply to  shawnmmatthews

What’s the specific article you’re referring to?
The link point to a list of articles, but I’m looking for information on how to achieve this in Drupal 8 (if possible, again…).

Steve Brown
Steve Brown
6 years ago

Thanks for the article, Steve. I’m having a problem getting 2 field values (category and subcategory (title)) to appear in the drop-down list in my Software Documentation content type. Only the subcategory appears. This is a problem because the same subcategory name can appear under more than one category. In your example, your ER field has 2 fields. So what am I missing? I’m using Drupal 8. As I finished typing this, I see another comment saying “this is broken in Drupal 8.0+”. Could that be why it’s not working for me?

maikr
5 years ago

Is this still not possible in Drupal 8? 

I can create a page view with a formatted table, which also shows grouped sections of content.
But how can I use this ‘grouped list’ as the contents of a field on a content form?

Best regards,
Maik

6
0
Would love your thoughts, please comment.x
()
x