Main menu

Drupal comes with a lot of functionality ‘out of the box’. We add functionality by enabling modules. Sometimes tough, we do want to keep the functionality but we don’t want it to be displayed where the module displays it (in the menu).

Hiding tabs on the “/user” page

For example, Drupal’s user module does a lot of nice stuff. One of those things is letting users log in, creating accounts and let them recover passwords without the side admin having to get involved. This is nice functionality. We want this. But we might not like that those “Create new account” and “Request new password” links are displayed on the “/user” page as seen below.

We want to keep the functionality, but we don’t want all those links displayed on the same page.

How to hide menu-items?

Say hi to hook_menu_alter. This hook lets us change existing menu-items. (Menu-items such as those created by the user module.) Using this hook we can override all settings for each menu-item.

This means we can change the menu’s title, description, permissions, or even remove the page all together, with Drupal’s hook_menu_alter.

<.h3>Menu-items?

Menu-items are specified by hook_menu. Each menu-item is registered by its path. For instance, the link “Create new account” belongs to “user/register”. So, to disable that link we target the menu-item “user/register”.

The specifications describe what title, description, access settings, page arguments… to use. As said before, it’s specified in a modules hook_menu.

For instance, Drupal’s user module specifies the following for “user/register”:

  $items['user/register'] = array(
     'title' => 'Create new account',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('user_register_form'),
    'access callback' => 'user_register_access',
    'type' => MENU_LOCAL_TASK,
);

Menu-item’s “type” specification

Now, to just disable the menu-items, but keep the functionality, we change the menu-item’s “type” specifications.

The menu-item’s “type” specification specifies what kind of menu-item it is. Drupal provides us several options:

  • MENU_NORMAL_ITEM
  • MENU_CALLBACK
  • MENU_SUGGESTED_ITEM
  • MENU_LOCAL_ACTION
  • MENU_LOCAL_TASK
  • MENU_DEFAULT_LOCAL_TASK

By default, the menu type is MENU_NORMAL_ITEM which puts the menu-item in the site’s menu, usually the navigation menu.

The user menu displays the links as tabs. So it uses MENU_LOCAL_TASK and MENU_DEFAULT_LOCAL_TASK.

Type: MENU_CALLBACK

Anyway, to drop the link out of the menu we change the type to MENU_CALLBACK. This one is used to register a module’s path but to not display a menu-item for it. And that’s exactly what we want.

So, in summary, to hide the links on the user page we write the following code:

/**
 * Implements hook_menu_alter().
 *
 * We want to change the menu-items on the login form.
 */
function gluecode_menu_alter(&$items) {
  $items['user/register']['type'] = MENU_CALLBACK;
  $items['user/password']['type'] = MENU_CALLBACK;
}

And this hides the “Create new account” and “Request new password” links as shown below.

3 comments

Default avatar
Manning
Mon, 04/07/2011 - 17:55

Hello, This is exactly what I'm looking for. But where should I put this code in? Manning
Default avatar
Bob
Tue, 19/07/2011 - 22:44

Yes - Im new to drupal - where do you put this code ??
Default avatar
sac lancel en solde
Fri, 16/12/2011 - 17:43

Un <h1><a title="sac lancel" href="http://www.lancel-boutique.com/">sac lancel</a></h1> contient des diviseurs individuels et un top cinq voies, qui fournit aux gens avec des options de stockage supplémentaire. Il a une sangle rétractable primaires qui le rend facile à transporter lors de longs voyages de golf et sa <strong><a title="sacs solde" href="http://www.lancel-boutique.com/lancel-paris">sacs solde</a></strong> pochette accessibles bouteille d'eau est également un bonus supplémentaire à toute personne qui veut avoir un accès pratique à leurs bouteilles de boisson. Chaque golfeur a besoin d'un <h5><a title="sac brigitte bardot pas cher" href="http://www.lancel-boutique.com/collections-sacs-lancel/le-brigitte-bardot">sac brigitte bardot pas cher</a></h5> dimanche de style. Si vous n'avez pas un sac léger, que vous pouvez facilement transporter à chaque fois que vos amis vous invite à un <strong><a title="sac lancel en solde" href="http://www.lancel-boutique.com/lancel-paris">sac lancel en solde</a></strong> tournoi de mini-golf, II serait parfait pour votre utilisation. Il pèse moins de deux livres, ce qui en fait une alternative populaire à traditionnels sacs de luxe debout. Ce <h5><a title="lancel brigitte bardot pas cher" href="http://www.lancel-boutique.com/collections-sacs-lancel/le-brigitte-bardot">lancel brigitte bardot pas cher</a></h5> a également un séjour à charnière interne qui permet à un golfeur de le plier en deux pour faciliter le stockage. Il est également facile à atteindre quand il est debout sur le sol, donc il ne serait pas nécessaire de <strong><a title="solde sac lancel" href="http://www.lancel-boutique.com/lancel-paris">solde sac lancel</a></strong> se pencher à chaque fois que vous devez prendre vos clubs hors de lui. Si vous cherchez un sac complet, vous devriez envisager l'achat d'un <h3><a title="lancel.com" href="http://www.lancel-boutique.com/">lancel.com</a></h3> . Son châssis interne contient six diviseurs individuels qui peuvent vous aider à organiser vos clubs plus faciles. <a href="http://www.lancel-boutique.com/"><strong>http://www.lancel-boutique.com/</strong></a>