Drupal 8 Contextual Filter Based Upon Current User

2.4k views Asked by At

Somehow I am not getting it.

I have created a Taxonomy of Organizations. I have then added a custom required field to my User accounts call "Organization". I would like to create a view where the currently logged in user can only see a list of people that belongs to the same Organization as the currently logged in user and no others.

I have created the view just fine, and the list of users appears fine, but I cannot get the filtering and relationships to only show me the only the users that belong to the same Organization as the currently logged in user.

I could do this in SQL in like 2 seconds, but for some reason I am not getting how to do it in the Drupal interface.

I am running Drupal 8.

1

There are 1 answers

4
Kien Nguyen On BEST ANSWER
  1. Add a contextual filter User ID (to get the current user) enter image description here enter image description here

  2. Add a relationship Taxonomy term referenced from field_organization (to get the taxonomy term referenced by current user) enter image description here

  3. Add a relationship User using field_organization (to get the users referencing to the Organization taxonomy at step 2) enter image description here

  4. Change the relationship of all fields to field_organization enter image description here

  5. If you want to exclude the current user from the results, add another contextual filter User ID with field_organization relationship enter image description here Remember to scroll down and check the Exclude enter image description here