as the title says i'm trying to add a menu item to the user-menu. I'm using the following code:

function sawqr_menu() {
    $items['user/%user/qr'] = array(
            'title' => t('QR Code Management'),
            'page callback' => 'sawqr_view_embed',
            'page arguments' => array('qr_codes', 'page'),
            'access callback' => 'user_access',
            'access arguments' => array('Administer SAWQR'),
            'menu_name' => 'user-menu',
            'type' => MENU_SUGGESTED_ITEM,
            'weight' => 0

    return $items; /// forgot to add this from my module

If this is your real code, then you're missing the return $items; line at the end, looks good otherwise :)

Edit: You are using 'type' => MENU_SUGGESTED_ITEM which means that the menu item needs to be enabled manually in the administration. And when you do, it will show as a sub menu item of /user/%user, which basically means it is invisible because there the default secondary menu position only displays top-level menu items. Try MENU_LOCAL_TASK instead to have it show up as a local task.

P.S.: permission strings are usually all lowercase (they are a technical identifier, not a user facing label or so).

  • actually i just omitted that line by mistake.
    – Chad Payne
    Dec 28 '11 at 17:31
  • @ChadPayne: You seem to be using the wrong type, see my edited answer.
    – Berdir
    Dec 28 '11 at 20:50
  • Alright it seems the menu has been appearing but for some reason the permissions aren't allowing the admin user to see it even though they have access to everything. Thanks for your help it helped.
    – Chad Payne
    Dec 28 '11 at 22:21
  • So I've tried removing all access callbacks etc.. for the menu item but it still isn't showing in the menu page or on the actual menu. What could be happening? It does show up in the database and dsm() calls in the menu.admin.inc right up to the point it hits line 67 - menu_tree_check_access(). I've been reading up on that function but as far as i know if i don't specify a access permission then it should just allow viewing of it.
    – Chad Payne
    Dec 28 '11 at 23:08
  • Removing all access callbacks results in the opposite of what you want and means that nobody has access. So that's not going to work. Not sure why it shouldn't work with them, though. Make sure you typed the permission name correctly everywhere.
    – Berdir
    Dec 29 '11 at 8:52

hook_menu() needs to return $items in order to work.
I get tripped up by that a lot.

  • i actually just forgot to add that when copying the code from my module. any other idea as to why the menu item isn't appearing in my menus
    – Chad Payne
    Dec 28 '11 at 17:33
  • 1
    Did you clear caches? Are the permissions correct? Are you able to load the page by entering a URL manually?
    – Drupac
    Dec 28 '11 at 18:02
  • I clear the cache, and rebuild the menu using devel. I also clear my browsers cache as well. MEnu items don't show up in the menu or on the menu list items page. Permissions are set for my user
    – Chad Payne
    Dec 28 '11 at 18:07

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.