Score:1

Filter view based on current user's role and taxonomy terms

br flag

I have three content types.

  • Article
  • Basic Page
  • Custom Page

All the content types have a field_interests field, which can have multiple values, and which is an entity reference field to the interests vocabulary.

The taxonomy terms for that vocabulary are:

  • sports
  • songs
  • movies

I have three user roles.

  • Athlete
  • Singer
  • Actor

I want to create a view in which:

  • Athlete users can view nodes for which the value of field_interests is sports
  • The Singer users can view nodes for which the value of field_interests is songs
  • The Actor users can view nodes for which the value of field_interests is movies

I am assuming filter condition should be like this

( current user's role == athlete AND "field_interests"==sports ) OR
( current user's role == Singer AND "field_interests"==songs) OR
( current user's role == Actor AND "field_interests"==movies)
// if any user has multiple user roles 
( All current user roles in [Singer , Actor] AND All "field_interests" in [songs , movies] )

I saw similar questions and I don't know how to use those answers to my exact purpose.

cn flag
Roles in Drupal are not exclusive (each user can have multiple roles). So what should happen if a user has the roles of Actor and Singer?
ru flag
This will be much easier if you create 3 separate views, each view showing only one "interest". And then limit access to those views by assigning the corresponding permissions to your user roles.
Steve Siddu avatar
br flag
@Hudri Yeah, I tried that but, If I have to create 15 views which should display content based on role and suppose I have 10 roles , In that case I have to create 150 views . Which is , I feel not a good practice.
Steve Siddu avatar
br flag
@PatrickKenny In my case I'll make sure every user has a single role. but, In any case if user has roles of Actor and Singer, I want to add new condition like ```all current user roles in [Actor , Singer]```
Steve Siddu avatar
br flag
@PatrickKenny how can I set taxonomy term value dynamically [seeHere](https://drupal.stackexchange.com/questions/308415/how-to-add-filters-in-drupal-8-dynamically), need help
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.