I'm trying to use a combination of views, blocks, contextual filters, and taxonomy (most of which I'm only partially familiar with) to achieve a certain functionality for my drupal site. Here's the context:

Goal
I have two content types: User profile, and publications. Content in each type will have their own pages that can be viewed. There must be an association between these two types, where a publications's listed authors refers to the list of user profiles on the site. On each user profile page, there should be a block with a view that displays the title (and link) to each publication on the site that has that user listed as an author. This block should always display the correct publications based on the specific user profile that is displayed on the page.

Current Set-up
I have a taxonomy vocabulary where the terms are unique User IDs. Both the User Profile and Publications content types have fields that make a term reference to this vocabulary. I also have a block view that has manual filters to only show titles of Publication content. The block is set to display on any User Profile page.

My Attempt
I was thinking that it was possible to use the term selected by a User Profile page as an argument to a contextual filter to correctly select the relevant publications. After playing around with it, it seems like I can draw arguments from the User Profile's URL, but I don't think I want that. How can I feed the User Profile's selected taxonomy term as an argument to the block's contextual filter to get the correct publications?

Comments

John_B’s picture

You probably have to create a relationship in the block view which will be on the user page, to the taxonomy term, then to the content which has that taxonomy term.

Making a reference which involves a third entity (taxonomy) is of course doing it the difficult and potentially less performant way than making a direct entity references from user to publication (which can also be added as a relationship on a view, as a relationship in either direction).

In addition, a block view does not by default get fed other information from the page it is on, so in your contextual filter you need to specify validation. Making the contextual filter react to an element of the URL is the easiest and commonest though not the only way to use a contextual filter.

Simpler alternative: use EVA module. Make an EVA attachment on the User page which lists each piece of content (e.g. article title) where that user appears as a field (perhaps an entity reference field) on the content node.

Alternative possibly interesting if you are a developer: learn about this module https://www.drupal.org/project/relation.

Digit Professionals specialising in Drupal, WordPress & CiviCRM support for publishers in non-profit and related sectors

IsaacB’s picture

Thanks for your suggestions! I almost forgot to reply with my solution, so let me fix that!

Like you said, I think I trying to achieve my goal using methods that were more complicated than necessary. The problem I was encountering was that I don't have a wide understanding of the variety of modules that are available and how they can make some of my tasks easier. I've mostly been trying to use Drupal in its out-of-the-box state, which is a mistake. After doing some research based on your suggestions, I came to an easier solution.

I wound up using the Entity Reference module, along with the required Enity API module. Via this module, content types can support fields that refer to other nodes directly, and views can be configured to use these references as filters. This allowed me to cut out the taxonomy middle-man, which indeed made several processes a fair bit simpler. Thanks for setting me on the right track!