Reference fields and contextual filters

Rating

A reference field in showing for a given node, the links to the other nodes or taxonomy terms are visible. If you add a movie actors / actresses a link refers to the content of these people.

The reverse is more difficult. What if you want to show the films in which the actor plays a part? You might be in the content type to post a reference field for movies, but then you have dual input. This is not the way Drupal ...

Let us first look at the content type of the films. You can clearly see a reference field for the actors.

Screen001812.png

It is a node reference.


Screen001813.png

In the film 'Cleopatra' you see this example:

Screen001821.png

Elizabeth Taylor has played in many films, of course. Her name is so common in the nodes of the films. To make the reverse movement .. show all movies of a certain actor we need to first make a view. It is a listing of all films with the corresponding actors.

Screen001815.png

Screen001822.png

We get all the movies that are in our Drupal ... How we manage a node (actor / actress) to show only show the movies where they have played in? We will use a contextual filter. This is a filter that appears in the URL. If you look at Elizabeth Taylor, then actually you look at node 4 (in our case, of course). I can make clear to the view that he should show in the actor node only those films. 


Screen001816.png
Screen001817.png

Do not panic if you don't see any movies any  more .. To test you can now type the node ID in the preview window. In our case, (4) we become Elizabeth Taylor her movies.

Screen001819.png

 

OK. This works. How do we get this now linked to our content type? There are several ways. I choose the simple EVA module. Here you configure what type of content you want to link to.


Screen001818.png

It will appear in the displayof the content type.

Screen001820.png

And yes. When viewing the information of Elizabeth now comes with the filtered view of her films..

Screen001814.png

Contextual filters are widely used in Drupal. They are an essential tool in reference fields.