Entity Reference Views in Drupal 8: What Are They? Why & How to Use Them

Why would you use entity reference views in Drupal 8? How do they influence your experience as a Drupal content editor? What are they more precisely?

But first: what is entity reference?

And how do you use an entity reference view

Let's talk... specific examples, shall we? Real-life scenarios, where using an entity reference view would enrich the Drupal editorial experience:

 

1. But First: What Is an Entity Reference?  

First of all, it is a module. One that, luckily enough, is now part of Drupal 8 core.

When do you need it?

  • when you want a parent content to reference a child content element
  • when you need to associate a specific taxonomy term with a user account

In short: Entity Reference is your reliable ally each time you need to build relationships between certain entities...

 

2. And What Is an Entity Reference View?

Entity reference views in Drupal 8 have a powerful influence on... content editors' overall experience with Drupal.

How come? Well, just imagine putting together the content on a Drupal 8 website by assembling... fields. Lots and lots of plain, boringly displayed... fields. Now, when you add an entity reference view (or some of them) to the picture, you instantly add more... information.

More details for the content creators to choose from (and thus improve their own experience as content creators), details that will automatically enrich the end user's experience, as well...

Just compare a boring list of names to a list of names accompanied by titles, pictures and other personal information about the “names” included there.

 

3. Step-by-Step Guide on Using Entity Reference Views in Drupal 8

Now, let's see precisely how you can:

  • add an entity reference to a newly set up content view
  • style it, so that it displays precisely those searchable fields that you need it to
  • add your newly created entity reference view as a field

     

3.1. Create a Content View 

And this is going to be the view of the content that your Drupal editors will scan through and select from. 

For instance, it could be a view listing the speakers attending one of your company's next conferences:

Entity Reference Views in Drupal 8: Create a Content View

Image source: OSTraining.com

Next, click the “Add” Button, on top of the screen, and, from the drop-down menu that unfolds, select “Entity Reference”.

Entity Reference Views in Drupal 8: Add Entity Reference

Image source: OSTraining.com

Then, press the “Add” fields button (in the bottom right side of the screen).

Select the “This entity_reference (override)” in the “For” field, on top of the page.

Next, add the specific searchable fields that you want your content editors to be able to choose from.

Click “Settings” (neighboring the “Entity Reference list”)


Entity Reference Views in Drupal 8: Entity Reference Details

Image source: OSTraining.com

Then, once in the “Entity Reference: style options screen”:

  • in the “Search fields” section just set the fields that you want editors to search by (title, image...) in the autocomplete widget 
  • next, click the “Apply” button

Then, just give the referenced content view a preview, to make sure everything's looking great.

 

3.2. Add a Field with the Newly Created Entity Reference View

For this, just go to Home>Administration>Structure>Content types.

“Add a new field"... then select “Reference>Content” from the drop-down menu.

Entity Reference Views in Drupal 8: Add Entity Reference Field

Image source: OSTraining.com

Click Save.

Next, configure the right field settings (the “Reference method”, the “View used to select entities”...).

Save your settings.

Next, just click “Add content” and your newly created view will be automatically used by the data entry.

Note: in case you need an autocompleting checkbox, just go to Administrator > Structure > Types >... Form-display and simply change the widget type defined there.

The END!

And this is what they are, why and how to use entity reference views in Drupal 8. 

With both Views and Entity Reference now in Drupal core, it would be a pity not to take advantage of this convenience that hugely influences content editors' experience with Drupal...

Image by ElisaRiva from Pixabay