سؤال

When I visit www.example.com/user, there is a page that shows the login/password and as well as a "Request New Password" tab.

How do I remove this "Request New Password" tab from the user page?

هل كانت مفيدة؟

المحلول

The No Request New Password module is probably the easiest way to go, though you'll need to dig for the 6.x releases. This disables any request to user/password, so this path with neither be accessible directly nor display in menus/tabs/links.

Alternatively, you can put its main function into your own custom module:

 /**
  * Implementation of hook_menu_alter().
  */

 function MYMODULE_menu_alter(&$callback) {  
     $callback['user/password'] = array('access arguments' => array(FALSE));
 }

نصائح أخرى

You can change the permission so the page is not accessible:

function hook_menu_alter(&$menu)
{
  $menu['user/password']['access callback'] = FALSE;
}

This code will disable the page altogether, so it's not available to anyone.

If you are already using a custom module (called, for example, custom_module) you can hide the user/password tab using the following code.

function custom_module_menu_alter(&$items) {
  $items['user/password']['type'] = MENU_CALLBACK;
}

This doesn't show the tab, but the path is still accessible to the users who know Drupal has that path.

To hide it and disable it, use the following code.

function custom_module_menu_alter(&$items) {
  $items['user/password']['access callback'] = FALSE;
}

Setting the access callback to FALSE, the tab will not be accessible nor visible to any user, including the user #1.

In the last hook implementation that I shown, using $items['user/password'] = array('access arguments' => array(FALSE)); is wrong since:

  • Setting the access arguments to an array containing the FALSE value is not the correct way to avoid Drupal checks the user has the permission to see the route/menu.
  • Using that code, I am literally setting the route definition to an array containing just 'access arguments' => array(FALSE) with all the consequences that could happen if there is another module that re-enables the user/password tab for the currently logged-in user, and that module has hooks invoked after the hooks of your module. (With the example code I shown, this simply happens when the other module is called destiny_change_user_password_tab.)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى drupal.stackexchange
scroll top