How can I change the access callback for a page view (Views module)? I tried hook_menu_alter but realized that views uses the same hook to add the menu items defined by it - as a result of which, I am unable to have access to them.

Any way out?


3 Answers 3


Views allows you to set the acess within the UI, you can restrict based on roles or permission.

Usually that should be enought but if you need to set a custom access callback you can use hook_menu_alter but you will also need to make sure your module is called after the views hook_menu_alter, you can change the weight of your module in the database or you can use hook_module_implements_alter to make sure your module is called after the views module for the menu alter hook.

  • Sweet. hook_module_implements_alter is a good way out but it would be awesome if there was a lighter solution. Problem right now is that custom access functions in Views can take only static arguments. Jul 11, 2011 at 12:41
  • 1
    Thank you for this example, here is a detailed example of some of this code in action for this problem: tylerfrankenstein.com/code/… May 10, 2013 at 14:26

Try the Views Access Callback module.

Provides callback-based access control for Views.

Available callback functions are defined by modules using hook_views_access_callbacks() function (in the same way as in hook_perm()), then could be set in the view's "Access restrictions" configuration.

  • Thanks for this answer - the views_access_callback module is very useful, and it automatically passes any arguments your view has to the callback. It's easier than writing a Views plugin. It's cleaner than writing a hook_menu_alter() in a module that needs to have its weight increased in the system table (hook_module_implements_alter doesn't exist in D6)
    – rcourtna
    Jul 12, 2013 at 16:31

I can't directly answer that question, but you do have two options.

You can make a custom block and embed the view in it, and then hook_menu it into the system with access control.

The other option is to use a panel page, and add the view to a pane. You can then control access via the panels interface.

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.