Can you describe who to set up the view?

Comments

maximpodorov’s picture

You should create a view which shows anything you want. Just one condition: the view must have one argument (context filter) which will receive entity ID of the entity which has entity reference field you configure to use this formatter. So the common use case is to create view with relationship which connects the entity containing entity reference field and the entity which is references by this field; you should add context filter for the former entity's ID; you should add fields like title for the latter entity.

funkytraffic’s picture

Thanks, could you add a description based on a very common example?

Like: Reference from Node Type A to Node Type B. Setting up a View I would add which Context Filter exactly?

HorsePunchKid’s picture

Here's a specific example that I worked through, which might help you understand the structure.

I have a node type song with fields like title, duration, and key. I have another node type set_list. The set_list node type has an entity reference field to nodes of type song, naturally. I created a view called set_list_songs which I want to use on the set list page to render the list of songs. I added a contextual filter Content: Nid which is how the view knows which set list is being displayed. Then I added a relationship Entity Reference: Songs (note reference, not referencing) which tells the view how to pull out the songs for this set list.

The last step is to add some fields to the display. Keep in mind that this view is primarily on the set_list, so when I wanted to display the song title, duration, etc., I needed to choose that relationship on the configuration page when adding the fields. Otherwise, it would be trying to display the title, duration, etc. for the set list instead of the songs.

Hope that helps!

maximpodorov’s picture

A perfect explanation!

funkytraffic’s picture

Great, works for me too!

Only the field label should not be displayed if the field is empty?

maximpodorov’s picture

Status: Active » Fixed

The label showing issue is fixed. Thanks.

funkytraffic’s picture

Thanks, I can confirm this is working now.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.