View of an Entity that References the Same Entity with a Panels Argument

Posted on: October 3, 2015 - 11:12pm by Kevin Cobb

In this scenario we have three content types.

  • Degree
  • Professor
    • 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):

Entity Reference View

STEP 1

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)
    Contextual Filter NID
  • 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.

STEP 2

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".

STEP 3

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
    Argument Input on a View Drupal

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.

Pane Input Argument

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.

Faculty members view

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Latest from Blog

Stay In Touch

Subscribe to Our Newsletter

Stay informed on our latest news!

Subscribe to Dios Media feed