1

So I have a custom module that is adding 3 menu items (a main tab, and 2 sub-tabs). When navigating to the main tab (url: /casereports) the default_local_task is displayed as expected and both menu items (Case Reports and Jobs Completed) are active as expected. Everything is working fine except that when I click on the second tab (Jobs Created), the main tab (Case Reports) loses it's active status. I can't seem to figure out what I am missing here and why it is not picking up it's parent and the active-trail. Any ideas?

function casereports_menu() {
  $items = array();

  $items['casereports'] = array(
    'title' => t('Case Reports'),
    'page callback' =>'drupal_get_form',
    'page arguments' => array('casereports_completed'),
    'access arguments' => array('access content'),
    'menu_name' => 'features'
  );
  $items['casereports/default'] = array(
    'title' => t('Jobs Completed'),
    'type' => MENU_DEFAULT_LOCAL_TASK
  );
  $items['casereports/created'] = array(
    'title' => t('Jobs Created'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('casereports_created'),
    'access arguments' => array('access content'),
    'type' => MENU_LOCAL_TASK
  );
  return $items;
}

screenshot

screenshot

  • Try removing menu_name => 'features' from the second tab – JamesK Jul 27 '12 at 22:25
  • Does 'casereports' item have 'type' => MENU_LOCAL_TASK ? ie., Is case-reports menu item itself a tab or not ? – BEFL Jul 27 '12 at 22:46
  • @Sharan That part of it is already correct. The problem has something to do with using a custom menu. – JamesK Jul 27 '12 at 22:49
  • @JamesK I just wanted to know if "casereports" is a tab in itself or just a normal menu. – BEFL Jul 27 '12 at 22:56
  • @Sharan the 'casereports/default' item makes it both – JamesK Jul 27 '12 at 22:59
1

OK...so this basically ended up being more of an Open Atrium issue than anything else. Due to the fact that Open Atrium relies heavily on Features and Context, the style sheet was setup to deal with the classes added by those modules. Drupal's implementation of active-trail and active classes was working fine, however the theme's 'active' styles weren't setup to work without the classes added by the Context module.

I could either a) add a Context for the menu item added via my module (which is the route I took), or I could have (b) modified the CSS for the theme by adding a custom stylesheet.

Thanks for all the help guys, but I am embarrassed to say that in the end, it was just a bit of a theme problem from the Open Atrium install.

0
+50

I really can't tell why is this happening, but I can give suggestions for finding out why is it happening. The best way to start would be by checking the menu_router database table to verify what is the difference between the MENU_DEFAULT_LOCAL_TASK and the MENU_LOCAL_TASK items in the database. If that does not uncover any clues, then I would start looking at the theming layer for answers. I would start by using Firebug to see what is the name of the active tab CSS class for the MENU_DEFAULT_LOCAL_TASK item, then search Drupal core for that class. Once I found the function that is outputting the active tab CSS class, I would pepper it with breakpoints (or debug statements if not using a debugger), and see what makes it giggles, so to speak. This process should give you enough information to know why is the MENU_LOCAL_TASK not being marked as active.

  • I actually have done some of what you said, and already determined that they are using the same tab_parent and tab_root...so that is correct. Maybe you are right...I need to start looking into the theming layer. I'll report back what I find. – kevindeleon Jul 31 '12 at 19:40
  • So I did find that the parent tab is receiving the classes .active-trail and .active when the default tab is chosen (Jobs Completed). However, when 'Jobs Created' is chosen, the parent tab 'Case Reports' only receives the class .active-trail. The css for the the theme is only targeting parent tabs with the .active class. So I could just tweak the css, but it still interests me why it's not receiving both classes. Themeing maybe, or is it a bug in the core? – kevindeleon Aug 1 '12 at 2:54
  • I am going to go ahead and throw the bounty points your way since your answer got me thinking down the correct path. It wasn't the "correct" answer so to speak, but it definitely got me moving in the right direction. – kevindeleon Aug 1 '12 at 16:17
  • Yup, that was the purpose of my answer, not to serve as a definitive, conclusive answer, but as a path to finding one. Glad to know it helped ;) – amateur barista Aug 1 '12 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.