I created a HTML table view to show the current "listings" the user has created. I have everything set up (I think), but I am looking in how I can restrict access. The view is suppose to be a tab on the user profile page with the title of "My Listings". I need to only show it to the profile owner and also make it so people can't access it via URL itself (bypassing the tab)

I remember this was doable back in the Drupal 6 days, but my memory fails me.

Path: /user/%/listings (contextual filter % is set to UID)

So if user 1 goes to /user/1/listings They should see a tab next to View | Edit that says "My Listings"

But if user 4 goes to /user/2/listings they shouldn't see the "My Listing" tab. But if they go to /user/4 they should see their "my listings" tab.

Thanks for the help.

1 Answer 1


set your view path to:


Add a contextual filter of: author uid, and set 'WHEN THE FILTER VALUE IS NOT IN THE URL' to User ID from logged in user.

Add a menu 'Menu Tab'.

For access you have various options. Here is a simple one.

Install Views PHP and set access to PHP, then add this bit of code in there:

global $user;
return $user->uid == arg(1);
  • You can add the above mentioned PHP Code in same Contextual Filter by checking 'Specify validation criteria', then select PHP Code from Validator. Dec 19, 2015 at 20:28
  • But I would still prefer some other way rather than putting PHP Code in the database. Dec 19, 2015 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.