Drupal 8 - How to show view user data to owner user only

May 14, 2019

Introduction to Problem

I have some data related to users. For example: which are the files users have downloaded. This information is private to user. I wanted to show users their history of activities. Views are fantastic module to create a view block for this kind of purpose. I configured it to show data I wanted, and show it on user profile page.

But, the issue now is, everybody can see everybody’s data. The objective was to show user data to current logged-in user only. ANd, the data must belong to him only.

Its not like User-A should be able to see User-B data.

Solution

  • In your view, click on Advanced, then Add a Relationship

Drupal Views

  • Search for Author. Add it.

Drupal Views

  • After selecting, on next screen. Click on Require this relationship

Drupal Views

  • Add a Filter. Search for Current user.

Note: This field will be visible only when you have added Relationship, as mentioned above

Drupal Views

  • Select relationship of author, which you just created in above steps.
    • In Operator, select Is equal to
    • On right hand side, under option Is the logged in user, select Yes

Drupal Views

Save the view. Thats it. Note: This post does not include which fields to show, on which page to show.

Enjoy…


Similar Posts

Latest Posts