2

If I use

theme('links', array('links' => menu_navigation_links('main-menu'),
'attributes' => array('class'=> array('links', 'main-menu')) ));

It will print the links in my Main Menu. I need to print the links that are created by my custom module, but I do not know what the system menu name is.

For instance:

 //hook_menu
 function custom_menu() {

     //admin page
     $items['admin/custom'] = array(
     'title' => t('Custom Admin Page'),
     'description' => t('Manage Custom Module'),
     'page callback' => 'custom_admin_page',
     'access arguments' => array('access toolbar'),
     'type' => MENU_NORMAL_ITEM,
     );

     //add event
     $items['admin/custom/add'] = array(
     'title' => t('Add Custom'),
     'decription' => t('Add custom'),
     'page callback' => 'custom_add',
     'access arguments' => array('add custom'),
     'type' => MENU_NORMAL_ITEM,
     'file' => 'custom_add.inc',
     'file path' => drupal_get_path('module', 'custom') . '/includes',
     );

The page 'admin/custom' automatically goes into my administration menu, and the page 'admin/custom/add' is seen under the admin/custom link when viewing all of the links in the administration menu, but I want to print that menu (admin/custom) on the 'admin/custom' page so that I can see the link 'admin/custom/add'.

2 Answers 2

1

Menus and paths are slightly different things...in hook_menu() you're defining paths that can be consumed; menus create the links to those paths - the two concepts aren't necessarily related (a path can exist without a menu link).

You can assign a particular router path to a menu using the menu_name property in your hook_menu() items, but that menu needs to exist already.

Fortunately Drupal provides a method for adding links to the top of a page through hook_menu(), and you only need to change one line:

$items['admin/custom/add'] = array(
  'title' => t('Add Custom'),
  'decription' => t('Add custom'),
  'page callback' => 'custom_add',
  'access arguments' => array('add custom'),
  'type' => MENU_LOCAL_ACTION, // <-- This one changed
  'file' => 'custom_add.inc',
  'file path' => drupal_get_path('module', 'custom') . '/includes',
);

That will put a link to 'Add Custom' at the top of the 'admin/custom' page; if you're using the Seven theme for administration it'll look like the 'Add Content' link on the content admin page:

enter image description here

5
  • that worked! That added the link to the 'admin/custom' page! I can't ask for too much at this point, but just wondered if I can change the icon. The plus sign looks great for 'add', but the next one will be edit.
    – nitsuj
    Commented Apr 9, 2013 at 20:54
  • The icon comes from CSS so you could probably just target the 2nd link (.action-links li:eq(2) a { background-image: /path/to/img) })
    – Clive
    Commented Apr 9, 2013 at 20:57
  • That's what I figured, but I wasn't sure if it was a directive that could be changed via Drupal hook. Thanks
    – nitsuj
    Commented Apr 9, 2013 at 20:58
  • Any way to order the links?
    – nitsuj
    Commented Apr 9, 2013 at 21:04
  • Sure, you can add a weight integer property to menu items, lower items appear first
    – Clive
    Commented Apr 9, 2013 at 21:08
-1

You should see hook_menu path added to navigation menu not showing up.

You need to change the following line of code.

'type' => MENU_NORMAL_ITEM,
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.