I have an entity type with a field collection that I want to display as table within the main entity display. I have created the view as a block view and added it as a block field using Display Suite.

However items that don't belong the containing entity appear in the display. In effect the embedded view displays all the field collections items, instead of those added to the containing entity.

The Contextual filters and the Relationships in Views UI don't display a means of linking the collection items to the host node.

Is there a way of filtering the view by the node?


It is rather counterintuitive because the way the settings that need to be changed are labeled. The idea is to filter the view by the Node Id for the containing entity, but that doesn't show up immediately in any of the places you expect to see it..

The first step is to add a Relationships. When you click the Add button you get the option for applying to Add Displays or This block (override). In my case I am doing it for only that view so I chose This block (override).

The relationship I choose is Field collection item (Entity with theConfig Type (field_system_config_type).Config Typeandfield_system_config_type` are the friendly and machine names of the field collection.

The select list for choosing which category to filter on is redundant because Field collection item is the only one there.

The next stage is to choose the Contextual filter. This order has to be followed because unless the Relationship is chosen first, the right elements to select for the Contextual filter don't show up.

The element to select here is the node id for host entity - Content: Nid. It is easier to type it exactly as there are quite a number to choose from.

You then select it and click Apply (this display). After that there is a message This display does not have a source for contextual filters, so no contextual filter value will be available unless you select 'Provide default'. You click on Provide default and in the 'Fixed value select Content Id from URL and click on Apply (this display)

This returns you back to the main Views UI screen and you can save it now.

If you know the node ids of some of the content types, you can test it by typing them in the Update preview box and see the list of field collections they match.

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.