I want to create an advanced view in Drupal 8 using contextual filters and relationships, but I fail.


I have three content types:

  1. Programme
  2. Module
  3. Testimonial

Testimonials may span programmes and Modules, and when they are added to the site, the author selects to which Modules and Programmes the Testimonial applies. This is done via an entity reference field in Testimonial allowing selecting both Programmes and Modules it applies to (I can change this if necessary, this is under development).

Additionally, Programmes allow to configure which Modules are part of it.

Both Programmes and Modules are configured to use Pathauto URLs of the format service/coaching/programmes/[node:title] and service/coaching/[node:title], respectively.


I want to create a block view that shows all testimonials that apply to the currently displayed programme or module (I will control that through configuring for which content type the block will be displayed).

If the displayed node is a Module, I want to show only those testimonials that apply to that module.

If the displayed node is a Programme, I want to show all testimonials that apply to the Programme and all its related Modules.

If the the displayed node is the front page, I want it to show all testimonials regardless the configured Modules and/or Programmes.

I got as far as adding a relationship to the view (of type Testimonial teasers) that points to content referenced in the entity reference field mentioned above, and a simple contextual filter based on the node ID (see below).


1. Pathauto probem

I can configure the contextual filter for /node/<id> style URLs and simple filtering happens for the currently displayed node. But I cannot get the filtering to happen when I want to use Pathauto URLs - this suggestion came somewhat close, this got me to the right direction but not quite there.

I am aware that the fancy "Raw value from URL" option for configuring when the filter is not available has a checkbox for "Use path alias", but I couldn't find any explanation for its behaviour or the relationship/interference with sibling option "Path component numbering".

There is also the option to configure a validator, as mentioned in the last reference I gave, but that reference talks about Taxonomies while I am dealing with Pathauto URLs... There is a Pathauto validator, but I have no clue as to what that does.

All I want is for the pathauto URL to be somehow translated into the node ID to be available for contextual filtering! Argh!

2. Hierarchical content types

How do I add relationships (I guess that is what I need to do) so that I get the desired result to display either Module-specific testimonials for a displayed Module node, or Module and Programme related testimonials when a Programme node is displayed?

I somehow have never managed to crack the mental image or concept of relationships in Views - they seem very unintuitive to me...

Thanks for any help on this.

  • Somehow, I was stupid. Or I don't understand Views. :-) Either way, once I tested the view using the simple Contextual Filter "Content:ID" on the site, it worked. But the good engineer I am I tried to test the view before I used it on the test site in the preview - using the pathauto path instead of the node id - preview apparently does NOT resolve the pathauto URL to node ID! So this is resolved, but the hierarchical content type problem still remains... – MDr Jul 29 '19 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.