Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Bob.the.builder on
Hi all,
I'm trying to code a multi-tier drop down menu from within my module.
In the module I have inserted the menu items below:
// myModule.module
function league_menu() {
$items['myModule'] = array(
'title' => 'My Module Options',
'expanded' => TRUE,
'menu_name' => 'main-menu',
);
$items['myModule/admin'] = array(
'title' => 'My Module Admin',
'page callback' => 'myModule_admin',
'expanded' => TRUE,
'access arguments' => array('access content'),
'menu_name' => 'main-menu',
);
return $items;
}
... however, the 'admin' menu item is not displaying. I am using a custom theme, in which I have in the template file:
// template.php
function myTheme_links__system_main_menu($variables) {
$html .= " <ul class='menu'>\n";
foreach ($variables['links'] as $link) {
$html .= "<li>".l($link['title'], $link['path'], $link)."</li>";
}
$html .= " </ul>\n";
return $html;
}
And in the page file:
print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'clearfix', 'main-menu'))));
I have googled for many hours. I am stuck. Please would anyone mind giving me some guidance as to how I make menu options show from the module I am creating? I would really appreciate any help you would offer.
Comments
Cache ?
Did you clear the cache after creating hook_menu() ?
Did you debug your code once
Did you debug your code once after cleared cache . Is following function is getting executing, if yes then check whether data is coming for
$variables['links']
.As I have seen your code, you are using l() function and for third parameter you are sending complete
$link
array. I think there is chance of mistake because it should be an associate array of associated options. But I am not sure where you are exactly stuck, not sure either your call back function is executing or not.Please confirm whether your call back and theme function is executing.
Pushpinder Rana #pushpinderdrupal
Acquia Certified Drupal Expert