Main menu

Last post I talked about modifying the permissions of an existing module. We could do the same to limit the functionality of a module.

How to limit the functionality of an existing module

By returning FALSE on a menu-item’s access callback we prevent all users access to the page and hence, to the functionality.

We do this by implementing hook_menu_alter so we can alter the existing menu-item.

Example, please

In the example below we drop Drupal user’s module’s functionality to allow users to request a new password. (I know, this is not something that we want to disable, but it’s just for demonstration purposes).

/**
 * Implements hook_menu_alter().
 *
 * We want to disable user/password.
 */
function gluecode_menu_alter(&$items) {
  $items['user/password']['access callback'] = FALSE;
}

Now, not only does the tab “Request new password” disappear but also the page “user/password” is inaccessible.

It has been disabled for all users, including superadmin user 1.

2 comments

Default avatar
Juicy Couture outlet
Mon, 19/03/2012 - 07:16

The content of this field is kept private and will not be shown publicly
Default avatar
skyfox
Mon, 26/03/2012 - 06:53

Very good article, let a person shine at the moment!