0

I am learning how to use hook_menu(). I am at a point where I have a question and not figure it out. I have a local task button inline with View and Edit and I want 4 sub-local_task buttons. See chart below.

View | Edit | **Outcomes** |

*Outcomes Viewer* | Add New User | Add Bulk Ghost | Registration Report

However, the first button(Outcomes Viewer) is missing and I cannot figure out how to get it to show up. Below is the menu code within the function. The Outcomes Viewer is a view. I am mixing this with some custom code and views as well. (*Drupal 7, Views 3)

$items['node/%node/ecg-outcomes'] = array(
    'title' => 'Outcomes',
    'access arguments' => array(1),
    'type' => MENU_LOCAL_TASK,
    'weight' => 50,
  );
  $items['node/%node/ecg-outcomes/'] = array(
    'title' => 'Outcomes Viewer',
    'access arguments' => array(1),
    'page arguments' => array(1),
    'type' => MENU_LOCAL_TASK,
    'weight' => -10,
  );
  $items['node/%node/ecg-outcomes/add-bulk-ghost'] = array(
    'title' => 'Add Bulk Ghost',
    'page callback' => 'entity_ghost_participant_report',
    'page arguments' => array(1),
    'access callback' => 'entity_ghost_participant_access_report_tab',
    'access arguments' => array(1),
    'type' => MENU_LOCAL_TASK,
    'file' => 'entity_ghost_participant.reports.inc',
    'weight' => 11,
  );
  $items['node/%node/ecg-outcomes/add-new-user'] = array(
    'title' => 'Add New User',
    'page arguments' => array(1),
    'access arguments' => array(1),
    'type' => MENU_LOCAL_TASK,
    'weight' => 14,
  );
  • If you can reduce the scope of the code and (thus the question), I'd try it locally to work it out. As it is though, the posted code has a lot of dependencies, so I can't easily do that. The only thing that sort of stands out to me is that you don't have a MENU_DEFAULT_LOCAL_TASK, which you might want. Can't recall having used it recently though, so it might not be relevant. – Letharion Oct 28 '14 at 20:23
  • I copied your code into a module and it works. - imgur.com/ZVDXzIE - the only other things I did was added dummy access & page callback functions to match your items and removed the 'file' param for my ease. – rooby Oct 29 '14 at 6:29
  • I would say the problem relates to the fact that your outcomes views page is a view, because mine was not. Maybe something conflicting with your views path/menu settings and this menu hook. – rooby Oct 29 '14 at 6:31
0

You need 3 menu items and 2 view pages. The parent menu and the default menu will share some configuration.

  $items['node/%node/ecg-outcomes/add-new-user'] = array(
    'title' => 'Add New User',
    'page callback' => 'SOME CALLBACK',
    'page arguments' => array(1),
    'access arguments' => array(1),
    'type' => MENU_LOCAL_TASK,
    'weight' => -9,
  );
  $items['node/%node/ecg-outcomes/add-bulk-ghost'] = array(
    'title' => 'Add bulk',
    'page callback' => 'SOME CALLBACK',
    'access arguments' => array(1),
    'page arguments' => array(1),
    'type' => MENU_LOCAL_TASK ,
    'weight' => -8,
  );
  $items['node/%node/ecg-outcomes/registration-report'] = array(
    'title' => 'Registration Report',
    'page callback' => 'SOME CALLBACK',
    'access arguments' => array(1),
    'page arguments' => array(1),
    'type' => MENU_LOCAL_TASK ,
    'weight' => -7,
  );

  return $items;

As the outcome-viewer is set up as a view and you want it as the default menu tab, you need to set up two almost identical pages in your view as follows:

View Page 1:

Path: node/%/ecg-outcomes
Menu: Type : Menu tab, Title : Outcomes, weight : 50

View Page 2:

Path: node/%/ecg-outcomes/outcomes-viewer
Menu: Type : Default menu tab, Title : Outcomes Viewer, weight : -10 

METHOD 2 I think it can also be done with 4 menu items and 1 view page, in which case you only define view page 1, and include this menu item:

$items['node/%node/ecg-outcomes/outcomes-viewer'] = array(
    'title' => 'Add New User', // NO page callback and access callback necessary
    'type' => MENU_LOCAL_TASK,
    'weight' => -9,
);
| improve this answer | |

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.