View of an Entity that References the Same Entity with a Panels ArgumentPosted on: October 3, 2015 - 11:12pm
In this scenario we have three content types.
- With an Entity Reference field that references a Degree
- Basic Page
Our goal is to create a Basic Page that will show certain professors based on a particular degree. For example, we create a page that has content related to the Business Administration degree(s). We want to pull professors that relate to this degree.
Here's a shot of the view (click for larger view):
First create a view of Professors and don't check Page or Block on the creation screen. Instead we will use a Views Content Pane. If you don't see this as an option, install ctools. In our Professor view, we add the Node ID (NiD) as a contextual filter. On the next screen:
- When the filter value is NOT available: Provide Default Value -> Content ID from URL.
Also you need to specify a Validation Criteria (see screenshot below)
- At the bottom of the above screenshot, change the "Filter value format" select box to "Node IDs separated by , or + ". This is important if you want to reference multiple nodes.
Now add the Degree Reference as a relationship. And be sure to use "A bridge to the Content entity that is referenced via field_degree_entity_reference". And be sure to check "Require this relationship".
Our last step is to specify how our basic page will pass an argument to the view. This is the most important step to understand when working with complex views. There are a few ways we can pass this argument from the page node to the view. Since I use panels and panelizer, and considering I don't want to add another field to my Basic Page content type, I will use a Panels Argument.
- Under the Pane Settings column -> Click Edit beside Argument input.
Under Content: Nid source, select Input on pane config
Now our View is finished, but we aren't. When adding this Views Content Pane to a page, it will ask for a node ID.
You will need to find the node ID numbers for the degrees you want to reference and enter them here. Now your page should show the professors that are related to the degrees you just specified.