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:
- Change the name of the function to match your theme name, and...
- Change the name of the menu to match your menu name
<span style="color: #000000"><span style="color: #0000BB"><?php<br></span><span style="color: #FF8000">/**<br>* Implements hook_page_alter().<br>*<br>* Add our own menus for Menu Mini Panels.<br>*<br>* This function does two things:<br>* 1. Prepare the links.<br>* 2. Build the output.<br>*<br>* Rename to match your module or theme, then add your menu name.<br>*/<br></span><span style="color: #007700">function </span><span style="color: #0000BB">themeName_page_alter</span><span style="color: #007700">(&</span><span style="color: #0000BB">$page</span><span style="color: #007700">) {<br><br> </span><span style="color: #FF8000">// Replace "menu-my-menu-name" with your menu name<br> </span><span style="color: #0000BB">$menu </span><span style="color: #007700">= </span><span style="color: #0000BB">menu_navigation_links</span><span style="color: #007700">(</span><span style="color: #DD0000">'menu-my-menu-name'</span><span style="color: #007700">);<br><br> </span><span style="color: #FF8000">// Don't change anything below here...<br> </span><span style="color: #007700">if (!empty(</span><span style="color: #0000BB">$menu</span><span style="color: #007700">)) {<br> </span><span style="color: #0000BB">menu_minipanels_prepare_links</span><span style="color: #007700">(</span><span style="color: #0000BB">$menu</span><span style="color: #007700">);<br> }<br><br> </span><span style="color: #0000BB">$output </span><span style="color: #007700">= </span><span style="color: #DD0000">''</span><span style="color: #007700">;<br> foreach (</span><span style="color: #0000BB">menu_minipanels_panels</span><span style="color: #007700">(</span><span style="color: #0000BB">NULL</span><span style="color: #007700">, </span><span style="color: #0000BB">NULL</span><span style="color: #007700">) as </span><span style="color: #0000BB">$mlid </span><span style="color: #007700">=> </span><span style="color: #0000BB">$minipanel_name</span><span style="color: #007700">) {<br> </span><span style="color: #0000BB">$output </span><span style="color: #007700">.= </span><span style="color: #DD0000">'<div class="menu-minipanels menu-minipanel-' </span><span style="color: #007700">. </span><span style="color: #0000BB">$mlid </span><span style="color: #007700">. </span><span style="color: #DD0000">'">' </span><span style="color: #007700">. </span><span style="color: #0000BB">_menu_minipanels_render_panel</span><span style="color: #007700">(</span><span style="color: #0000BB">$minipanel_name</span><span style="color: #007700">) . </span><span style="color: #DD0000">'</div>'</span><span style="color: #007700">;<br> }<br><br> if (!empty(</span><span style="color: #0000BB">$output</span><span style="color: #007700">)) {<br> </span><span style="color: #0000BB">$page</span><span style="color: #007700">[</span><span style="color: #DD0000">'page_bottom'</span><span style="color: #007700">][</span><span style="color: #DD0000">'menu_minipanels'</span><span style="color: #007700">] = array(<br> </span><span style="color: #DD0000">'#markup' </span><span style="color: #007700">=> </span><span style="color: #0000BB">$output</span><span style="color: #007700">,<br> );<br> }<br>}<br></span><span style="color: #0000BB">?></span></span>
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.