1

Can't seem to get hook_menu to work at all. I'm using the following code:

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

  $items['node/%node/mymodule-product'] = array(
    'title' => 'Edit Product',
    'page callback' => 'mymodule_product_redirect',
    'page arguments' => array(1),
    'access callback' => 'edit any commerce product entity',
    'weight' => 6,
    'type' => MENU_LOCAL_TASK,
  );  
  dsm('check');
  return $items;
}

dsm() from the devel module is outputting fine when I clear the site cache, so the hook is firing, however for whatever reason the link is refusing to display on the node tabs.

Visiting any of the node tabs already displaying, outputs the following errors:

Notice: Undefined index: access in _menu_translate() (line 778 of includes/menu.inc).
Notice: Undefined index: access in menu_local_tasks() (line 1892 of includes/menu.inc).

And manually going to a page that would be defined in hook_menu outputs a load more errors in the same vein:

Notice: Undefined index: access in _menu_translate() (line 778 of includes/menu.inc).
Notice: Undefined index: access in menu_get_item() (line 464 of includes/menu.inc).
Notice: Undefined index: access in menu_execute_active_handler() (line 499 of includes/menu.inc).
Notice: Undefined index: access in menu_tree_page_data() (line 1167 of includes/menu.inc).
Notice: Undefined index: access in menu_tree_page_data() (line 1167 of includes/menu.inc).
Notice: Undefined index: access in menu_local_tasks() (line 1845 of includes/menu.inc).
Notice: Undefined index: access in menu_tree_page_data() (line 1167 of includes/menu.inc).
Notice: Undefined index: access in menu_tree_page_data() (line 1167 of includes/menu.inc).
Notice: Undefined index: access in menu_tree_page_data() (line 1167 of includes/menu.inc).

While these are all only PHP Notices, I assume they still may be relevant.

Thanks!

5

'access callback' needs to be a function name. The function should return TRUE or FALSE;

From the API:

"access callback": A function returning TRUE if the user has access rights to this menu item, and FALSE if not. It can also be a boolean constant instead of a function, and you can also use numeric values (will be cast to boolean). Defaults to user_access() unless a value is inherited from the parent menu item; only MENU_DEFAULT_LOCAL_TASK items can inherit access callbacks. To use the user_access() default callback, you must specify the permission to check as 'access arguments' (see below).

"access arguments": An array of arguments to pass to the access callback function, with path component substitution as described above. If the access callback is inherited (see above), the access arguments will be inherited with it, unless overridden in the child menu item.

This means you could ommit 'access callback' and use 'access arguments' instead:

// This will be true for users with the access content permission
'access arguments' = array('access content');
|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.