3

I have a module with a bunch of menu-items. Is it somehow possible to show the MENU_LOCAL_TASK's when a MENU_CALLBACK is called? The structure basically is like this:

  • A normal menuitem in the user-menu
  • Some local tasks
  • 'test/%user_uid_optional/test2' in this example would be an overview-Page with several links as defined in in the last item.

This all works great, except I want the local tasks to be visible when the user clicks on 'test/%user_uid_optional/test2/%test'. Since I don't have breadcrumbs that's the only easy way for the user to get back to the overview page. Any idea?

function test_menu(){
  $items = array();  
  $items['test/%user_uid_optional'] = array(
    'title' => 'test',
    'page callback' => 'test_whatever',
    'page arguments' => array(1),
    'access callback' => 'user_view_access',
    'access arguments' => array(1),
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'user-menu',
  );

  $items['test/%user_uid_optional/test1'] = array(
    'title' => '...',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -20,
  );
  $items['test/%user_uid_optional/test2'] = array(
    'title' => 'test2',
    'page callback' => 'test_whatever_b',
    'page arguments' => array(1),
    'access callback' => 'user_view_access',
    'access arguments' => array(1),
    'type' => MENU_LOCAL_TASK,
    'weight' => -15,
  );
  $items['test/%user_uid_optional/test2/%test'] = array(
    'title' => '...',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('test_whatever_d', 1, 3),
    'access callback' => 'user_view_access',
    'access arguments' => array(1),
    'type' => MENU_CALLBACK,
  );
  return $items;
}
0

never mind, menu_set_active_item('test/%user_uid_optional/test2') in test_whatever (last callback in example) seems to work.

Both item, 'test/%user_uid_optional' and 'test/%user_uid_optional/test2', are active and visible, and the drupal_get_form is executed, so who cares about beauty :)?

| improve this answer | |
  • You could also send the url as a parameter to page callback – M a m a D Mar 27 '15 at 20:42

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.