Adding custom access condition to menu item.

  • 5 June 2013
  • mohit.aghera
As Drupal is hailed as good CMS if you want to alter any existing thing.
The hook architecture of drupal makes it possible to alter any thing.
 
You can also add custom acess callback for any menu item.
To add custom menu access callback you can user hook_menu_alter() function.
 
As per the documentation this hook Alter the data being saved to the {menu_router} table after hook_menu is invoked.
 
This hook is invoked by menu_router_build(). The menu definitions are passed in by reference.
Each element of the $items array is one item returned by a module from hook_menu. Additional items may be added, or existing items altered.
 
Alter the user/%user/edit access callback
 
/**

 * Implements hook_menu_alter().

 */

function YOURHOOKNAME_menu_alter(&$items) {

  // Define the new accesscallback

  $items['user/%user/edit']['access callback'] = 'user_access_profile_callback';

}


function user_access_profile_callback() {

//Check your condition and restriction 

//Return true if condition successful.

//Else false


}

 

Tags: 

Comments

Hi! Would you mind if I share your blog with my myspace group?

There's a lot of people that I think would really appreciate
your content. Please let me know. Many thanks

mohit.aghera's picture

You can share it on any social media. It is opensource. The more you share, the more you get and learn :)

Happy sharing..

Brucewayne's picture

You spared me a lot of time by giving this information. The hook architecture is quite useful. I never knew that there is an option to access callback from any menu item. Thank you so much for sharing this valuable info.

windows vista service pack 3

kendi102's picture

Thanks for such a knowledgeable information..that information is very useful..

soundcloud download

buysoundcloudnow.com

I got this website from my buddy who told me about this site and at the moment this
time I am visiting this web site and reading very informative content here.

Add new comment