I'm having a real big headache with the menu system and I almost thought that this module would solve all my problems in this life. But the reality hit back with local tasks.

Description of the setup

  • I have set up the node hierarchy and menu block modules
  • I created a node "Parent" and put it to the primary menu
  • I created a node "Child 1" and set its parent to be "Parent"
  • I created a node "Child 1.1" and set its parent to be "Child 1"
  • So the hierarchy is now
    Parent
    - Child 1
    -- Child 1.1

Description of the problem

  • I have a module that adds local tasks (tabs) to nodes in a similar way that the devel module does (Dev load, Dev render in the Devel module)
  • When I navigate to Child 1.1 and click on the local task (tab), the menu block provided by this module disappears completely!
  • I noticed the same thing happens with "Dev load" tab provided by the Devel module so I guess the problem is not just in my module.

Are there any known issues regarding local tasks? I searched the issue que but couldn't find anything.

All help is highly appreciated and if some additional information regarding the menu block settings or my hook_menu are needed I'm more than willing to give them.

Comments

masipila’s picture

Title: Menu block disappears when going to local task of a node (tab) » Menu block disappears when going to local task (tab) of a node
masipila’s picture

I've been struggling with the menus today and it looks like this is related to the menu wildcards that I use in hook_menu().

The setup is like this.

A "league" has tabs "League home", "Teams", "Games" and "Standings".

The tabs are defined like this:

  // League front page
  $items['competitions/leagues/%league_id'] = array(
    'title' => 'League title',
    'page callback'    => '_league_front_page',
    'page arguments'   => array(2),
    'access arguments' => array('access content'),
    'type'             => MENU_NORMAL_ITEM,
    );

  // Front page tab - the callback has already been defined
  $items['competitions/leagues/%league_id/home'] = array(
    'title'            => 'League home',
    'access arguments' => array('access content'),
    'type'             => MENU_DEFAULT_LOCAL_TASK,
    'weight'           => -10,
    );

  // Teams tab
  $items['competitions/leagues/%league_id/teams'] = array(
    'title'            => 'Teams',
    'page callback'    => '_teams',
    'page arguments'   => array(2),
    'access arguments' => array('access content'),
    'type'             => MENU_LOCAL_TASK,
    'weight'           => -7,
    );
  // "games" and "standings" similar to "teams"

"League" is in the special menu created with this module. When I navigate to any of the tabs (local tasks) (teams, games, standings), the whole League disappears from the menu.

I've been struggling with the wildcard loaders with normal menus as well (not created with this module). When I navigate to the tabs of the league (local tasks), the menu loses the trail and collapses.

masipila’s picture

Here's my workaround for this issue just in case somebody else is having similar problems with local tasks / tabs defined by wildcards in hook_menu.

My understanding of the situation is that the "local task" menu items are stored in {menu_links} database table in such a way that their parent menu item will collapse when we are viewing the tab. BUT it seems to be that this happens only when local tasks are defined using wildcards. If the local task is defined explicitly without wildcards, then the parent item won't collapse. This is a more generic phenomenon in the menu system but I'm almost sure it's the same reason why the menu block defined by this "Menu block" module disappeared as I described in the first post of this issue.

The CCK content.module is an example where the local tasks are defined using a Drupal 5 style foreach-loop. There the parent item won't collapse. Using a D5 style foreach-loop like this is something you probably want to avoid.

Anyway, finally to my workaround.

This is what I wanted to achieve. For now, you can see this in action on the old Drupal 5 based site:
http://www.curling.fi/en/competitions/finnish-championships

Primary menu item located in the top of the page:
- Leagues and Tournaments

"Submenu" of "Leagues and Tournaments" located on the left sidebar

Leagues and Tournaments
- Finnish Championships
-- Men's Championships 2010-2011 // this is a "league"
-- Women's Championships 2010-2011 // this is a "league"
-- Etc.

Each league has local tasks that are rendered as tabs:
- League home
- Teams
- Games
- Standings

So the whole menu hierarchy looks like this:

Primary menu
- Leagues and Competitions
-- Finnish Championships
--- Men's Championships 2010-2011 // league
---- League home // default local task
---- Teams // local task
----- Team A // callback menu item, link provided from the content of "teams" page
----- Team B
----- Team C
---- Games // local task
---- Standings // local task

So here's the way I worked it out for my D6 version of the module:

  • all paths are defined in hook_menu using menu wildcards
  • i.e. the local tasks are defined normally as local tasks using wildcards
  • In addition to this, I create explicit menu items to {menu_links} using menu_link_save function.
  • I do this for all local tasks (Teams, Games, Standings) and individual team pages (Team A, B, C) that belon under the "Teams" local task
  • Here is where the beauty of this menu block module jumps in: In the setting page of this menu block (admin/build/block/configure/menu_block/1) I restrict the Maximum depth of menu items to 3.
  • This way the "Men's Championships 2010-2011" is the last level that will be shown in the left sidebar menu BUT the deeper paths are still there and the menu will not disappear or collapse.

I hope this description helps if somebody else is struggling with menu wildcards and tabs created with local tasks.

masipila’s picture

Status: Active » Closed (works as designed)