1

I'm building a media server for my university. I have an "artist" content type for each performer, and then a 'track' content type for individual track (there are no 'albums', BTW). For each track, you can select the artist in edit mode, using an Entity Reference. So far so good!

On each Artist page is a block view with a table listing that artist's songs (the filter is 'show all tracks with a contextual filter of "artist"). Still good!

On each track page, I want to show "all tracks by this artist" as a table. I've tried "artist" as the contextual filter, and even tried both "referencing entity" and "referenced entity" as relationships, to no avail. If I put an artist NID in to the fixed value in the 'artist' contextual filter, it works fine. But I'm pulling my hair out, trying to get the artist to dynamically be referenced by the block's contextual filter, using the tracks 'artist' entity reference.

Am I missing something here? It really seems like it shouldn't be that hard. Thanks in advance!

  • Create a view -> filter node type: track -> relationship to field reference artist. Is this the way you have tried it? – Huelfe Sep 23 '15 at 13:44
  • You could probably do this dynamically, when you provide a default value in your contextual filter. Use PHP-Code, get the current node id -> load your node and return your artist nid. – Huelfe Sep 23 '15 at 13:55
  • I tried view -> filter node type: track -> relationship to field reference artist, and was surprised that it didn't work. If attempting to use PHP code...since contextual filters don't have a php option, would you recommend installing Views PHP, or is there a smarter module/means? – robgreeniowa Sep 23 '15 at 14:10
  • You don't have an php option? I don't think you need a separate module for this. – Huelfe Sep 23 '15 at 14:18
  • Aha, PHP Filter module hadn't been enabled on this install. Enabled and trying now.... – robgreeniowa Sep 23 '15 at 14:26
1

For the curious, with Huelfe's help I solved it with a custom PHP code, in order to obtain the applicable NID for that contextual filter. Seems like something that should be built in to Views already...! I've successfully reused the string or several other projects as well.

PHP Code Settings for Referencing a Node in Contextual Filter

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.