0

I need to write a "simple" feature in custom module which returns access denied for all the users except admin who tries to rich 'admin/structure/menu'. I've tried with hook_page_alter, hook_page_build and also with hook_menu_alter, but none of those functions work. Function hook_menu_alter is caching menus so it sets flag:

$items['admin/structure/menu']['access callback'] = FALSE

to all users and I (as admin) can't see this page also. Any help?

2

Menus are cached, but decision making functions aren't. So what you need is:

function MYMODULE_menu_alter(&$items) {
  $items['admin/structure/menu']['access callback'] = 'MYMODULE_menu_admin_access';
}

function MYMODULE_menu_admin_access() {
  return $GLOBALS['user']->uid == 1; // Or whatever makes most sense for your use case.
}
  • Thank you Clive. I've just found this solution and figured out how this works. This is the key "decision making functions aren't cached". And it all make sense. – David Mar 23 '15 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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