I want to make a subscription-page on the users-page. A user can flag terms. On the user-page there should

1) It's no problem to get a view with flagged content

  • relationship Flags [flag name]
  • contextual filter Flags: User uid

(see How to create view with user's flagged content?). The view shows only flagged terms.

2) It's no problem to get a view with flagged and not-flagged content

  • relationship Flags [flag name] with current user & include only flagged content NOT checked
  • path like /subscription

But as soon when i alter the path to user/%/subscribtion, every user can see other subscriptions by altering the path. When using this path with option 1), i see only flagged content (??). Removing the contextual filter, shows all content but accesible for everyone.

How can i restrict the access to the own subscriptions, showing flagged and unflagged terms?

1 Answer 1


Views only has 2 means to restrict access to Views: via a role or via a permission. Neither can help here so you'll have to use some other means to restrict the route path.

One way to go about this is to use the Views Access Callback module which was built for the purpose of dynamically checking access to a View. Once enabled, any module can implement hook_views_access_callbacks() to define a custom callback that can be used for permission checks.

It should be pretty easy to define a simple callback that inspects the current path to see if it belongs to the current user:

 * Implementation of hook_views_access_callbacks().
function MYMODULE_views_access_callbacks() {
  return array(
    'MYMODULE_access_account_subpages' => t('Access Account Subpages'),

 * Check that the user is the owner of the subpage.
function MYMODULE_access_account_subpages($account = NULL) {
  global $user;
  return (arg(0) == 'user' && $user->uid == arg(1));
  • Thanks, this comment was helpfull. Didn't know that there (by default) only 2 ways to restrict access. Because of the simplicity of the site (KISS) we use option 2 - in this way it's more clear for future admins.
    – MatthijsG
    Oct 4, 2016 at 7:31

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.