3

I've browsed through (and tested) every solution I could find here to this seemingly simple challenge.

I've got multiple content types (fx. News, Releases, Events, Videos etc.) that are referencing the content type "Artists" using an entity reference-field.

I want to have related content-blocks that shows the related news, releases etc. for the artists references in the node.

I've done this in D7 but it seems the approach have changed a bit since then (?).

What I thought I should do (with content type 'release' as example:

  • Create a related release-block in views
  • The a relationship 'Content using field_artist', require this relationship
  • Add contextual filter, select relationship, select 'content id from URL' as default value

But no results appear when doing this. If I remove the relationship I get 1 result, the node I'm already on...

What am I doing wrong?

2
  • 1
    Try removing the relationship and just have the contextual filter for 'content artist' with 'content id from URL' as default value. also Specify validation criteria to be content and type to be artist. – danuddara Jul 14 '17 at 3:23
  • 1
    You might have to work around this problem by starting with 'display all results' when there is no argument and then diving in to contextual filters. cannot give a correct answer for this.. sorry mate. just check the results after placing the block into a page. sometimes it is worth to see the results in there rather than the preview in views. – danuddara Jul 16 '17 at 20:54
0

As mentioned in the comments you don't need any Relationships to filter out the related content. Simply add the Contextual filter for your Entity Reference field, and configure it with a Default value to pick up Content ID from URL, and validation criteria to the Artist content.


You can use the Relationship if you need information other than the Artist node ID in your Views, for example, if you have an independent Views Page showing all Releases, and you want your Contextual filter to be in your URL showing the Artist name and not the ID number:

/releases/Beatles

for all Releases nodes referencing the Artist Beatles.

And it's still working the same as it did in Drupal 7, apart from the different wording in the names, you just added the wrong Relationship.

It should not be the 'Content using field_artist', but Content referenced from field_artist.

'Content using' that field are the nodes with the ER (News, Releases, etc.) so you're just pointing back to what you already have in your Views. This is a "backwards" Relationship.

The 'Content referenced from field_artist' Relationship is pointing towards the Artist nodes, and through adding that Relationship you'll have the Artist data available in your (Releases) Views. This is the Relationship you want to you in this case.

7
  • Finally got around to test this again, and you're absolutely right:) – Kristoffer Rom Jan 31 '20 at 10:40
  • I'm glad to help :) – prkos Jan 31 '20 at 11:23
  • Sorry to trouble you again @prkos, but actually it only works on nodes of the Artist content type. The views have no results on fx news posts or commerce products despite those nodes having an reference field to an artist. Is it possible to adjust something to make make it work across content types or do I need to use tags to achieve that? – Kristoffer Rom Apr 12 '20 at 9:26
  • IIUC your setup, that's expected. The ER field isn't automatically bidirectional, the way it's setup up in this question the other CTs (children) are referencing Artist (parent). The Contextual filter will take the "current" content ID and search all nodes of other CTs (all children) that reference the "current" Artist node (one parent). To show the Artist info (parent) on other (child) nodes you don't need Views. This can be configured on the Manage Display page for that CT. You can even create new (Display) View modes for this (don't confuse this with Views module). – prkos Apr 12 '20 at 19:21
  • Aha, well that makes sense for the ER-field. It didn't occur to me that it might not work both ways earlier:). I would however like to go with a views-based solution. I've used tags on my D7-site here (tambourhinoceros.net/products/armlock) which works well - it's just a bit unintuituve to have to tag the artist nodes with an artist tag identical toi the node's title. Let me know if you have an easy way to make the ER-field bidirectional, or if you think there's a better alternative than the tags. – Kristoffer Rom Apr 12 '20 at 19:37

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.