Hi,

In my code, I create some tabs using MENU_LOCAL_TASK.
Sometimes for some unknown reasons, the tabs disappears for some users.
I have the similar codes from other Drupal or contributed modules.

The only remedy that I can do is to truncate all cache tables and do menu_rebuild().
Can anyone help me?

Thanks.

Comments

nevets’s picture

What does your menu item code look like?

thekid’s picture

Thanks for the reply. I didn't expect it to be very fast.

This is the particular item that often disappears:

function mymodule_menu($may_cache) {
  if(_mymodule_check_admin(arg(1))) {
    $items[] = array(
      'path' => 'node/' . arg(1) . '/admin',
      'title' => 'Admin',
      'callback' => 'mymodulename_admin_page',
      'callback arguments' => array(arg(1)),
      'type' => MENU_LOCAL_TASK,
      'weight' => 2,
    );
  }
}

function _mymodule_check_admin($nid) {
  // there are some other checking, but I think you get what I mean...
  global $user;
  $q = 'SELECT uid FROM {og_uid} WHERE uid=%d AND nid=%d AND is_admin=%d';
  if(db_num_rows(db_query($q, $user->uid, $nid, 1)) > 0)
    return true;
  else
    return false;
}
nevets’s picture

You also reply on _mymodule_check_admin() which is called regardless of $may_cache and this may be the source of your problem. if(_mymodule_check_admin(arg(1))) { should be if(!$may_cache && _mymodule_check_admin(arg(1))) {. You will need to clear the menu cache after the change and given _mymodule_check_admin() returns true the user should see the tab.

thekid’s picture

Thank you, nevets. It may have worked.
I found a page that is missing the Admin tab and just by refreshing the page a couple of times and without having to truncate the tables, I can see the tab now.

I think I understand the use of $may_cache better.
Does this mean that mymodule_menu is actually called twice with $may_cache = true and $may_cache = false?

Is there an easy rule of thumb when an item should be listed when $may_cache = true and vice versa?

Thanks.

nevets’s picture

Correct about hook_menu being called twice (in Drupal 5).

Easy rule of thumb, if the menu item is surrounded by conditional logic it should be the case where $may_cache is false.

thekid’s picture

Thanks a lot!