Restrict "My Bookmarks" Tab only to the logged in user

Using the flag module, people can maintain lists of nodes on a Drupal site. To access their list of bookmarks, a tab on the users page can be provided. This tab is accessible at user/[uid]/bookmarks lets say. In the view you grab the ID from the URL and load all nodes which are flagged by this user.

Everythings pretty easy, the only problem is that this tab is accessible on every user page for everyone who has the permission "access user profiles". In many cases what you want is that someone can only access his own list of bookmarks.

This can be achieved easily - however the solution might not be very obvious:

  1. add a PHP validation to you argument (aka contextual filter)
  2. paste this snippet global $user; return $argument == $user->uid;

This translates to: If the current user id is not the same as the argument, do not validate. Meaning the view is hidden for others.