Menu Minipanels in Adaptivetheme - Instant Mega Menu

Menu Minipanels is a very cool little module that allows you to attach a mini panel to a menu item, which then pops open when you hover the menu item - aka instant mega menu!

A drawback of the current Menu Minipanels module is that it only works with Drupal cores Main and Secondary menus - not to worry, this tutorial is going to show you how to make it work with any menu. This is very important for many themes that do not use Drupal cores magic menus (because they suck) and prefer to use the "blocks and regions" concept. All of our commercial and open source themes work like this, because it allows much more flexibility, for example to use Menu Block module, Superfish and many other modules to slice, dice and transform menus any way you want.

hook_page_alter()

Sounds pretty scary, right? Well in a way it is, however it gives us the power to insert the code we need to make Menu Minipanels use our custom menu, which is awesome. I'm not going to muck around here, this is so easy we can avoid some long winded explanation and just go strait for the code.

You can do this in a module, or in your theme. Drupal 7 allows themes to use hook_page_alter(), so in your template.php file add the following code block - you only need to do two things:

  1. Change the name of the function to match your theme name, and...
  2. Change the name of the menu to match your menu name

<?php
/**
* Implements hook_page_alter().
*
* Add our own menus for Menu Mini Panels.
*
* This function does two things:
* 1. Prepare the links.
* 2. Build the output.
*
* Rename to match your module or theme, then add your menu name.
*/
function themeName_page_alter(&$page) {
 
 
// Replace "menu-my-menu-name" with your menu name
 
$menu = menu_navigation_links('menu-my-menu-name');

 
// Don't change anything below here...
 
if (!empty($menu)) {
   
menu_minipanels_prepare_links($menu);
  }

 
$output = '';
  foreach (
menu_minipanels_panels(NULL, NULL) as $mlid => $minipanel_name) {
   
$output .= '<div class="menu-minipanels menu-minipanel-' . $mlid . '">' . _menu_minipanels_render_panel($minipanel_name) . '</div>';
  }

  if (!empty(
$output)) {
   
$page['page_bottom']['menu_minipanels'] = array(
     
'#markup' => $output,
    );
  }
}
?>

And that's about it, you might need to clear you cache also. Now you can add your Menu Minipanel to any menu item in the menu you specified.

Last updated 19th July, 2012 - 9:46pm

Authored by Jeff Burnz on