2

Looking at user_menu() to check the answer for another question, I noticed the function contains the following definition.

  $items['admin/people/create'] = array(
    'title' => 'Add user', 
    'page arguments' => array('create'), 
    'access arguments' => array('administer users'), 
    'type' => MENU_LOCAL_ACTION,
  );

The page callback is not explicitly defined.

Reading the definition of MENU_LOCAL_ACTION given in hook_menu(), I read the following:

MENU_LOCAL_ACTION: Local actions are menu items that describe actions on the parent item such as adding a new user or block, and are rendered in the action-links list in your theme.

That doesn't explain which is the involved page callback that is called to handle that menu item.

Which is the page callback that is called to handle a MENU_LOCAL_ACTION menu item? Is there any other property that is necessary to define such menu items?

7

Router items can inherit properties from parent paths.

In this case, the page callback is inherited from the 'admin/people' path:

$items['admin/people'] = array(
  'title' => 'People', 
  'description' => 'Manage user accounts, roles, and permissions.', 
  'page callback' => 'user_admin', 
  'page arguments' => array('list'), 
  'access arguments' => array('administer users'), 
  'position' => 'left', 
  'weight' => -4, 
  'file' => 'user.admin.inc',
);

The fact that the menu item is a MENU_LOCAL_ACTION doesn't actually come into it, the same is true of any type of item.

So if you define a router item like this:

$items['mymodule/path'] = array(
  'title' => 'Something',
  'page callback' => 'mymodule_page_callback',
  'access callback' => 'mymodule_access_callback',
);

And then define one like this:

$items['mymodule/path/sub-path'] = array(
  'title' => 'Something',
  'type' => MENU_LOCAL_ACTION,
  'access callback' => 'mymodule_access_callback',
);

The page callback will be inherited from the 'parent' item.

  • 2
    I guess I got confused from what hook_menu() says about access callbacks: "only MENU_DEFAULT_LOCAL_TASK items can inherit access callbacks"; that is only true for access callbacks, not for page callbacks. I seem to have mentally extended that for all the menu callbacks. :) – kiamlaluno Jan 8 '13 at 11:26
  • I didn't know that actually ;) I'm positive the page callback will be inherited though, I've used that as a 'feature' loads of times – Clive Jan 8 '13 at 17:51
  • @Clive thanks for very easy and important explanation. – Fawwad May 29 '16 at 10:09

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.