function menu_minipanels_page_alter in Menu Minipanels 7
Same name and namespace in other branches
- 7.2 menu_minipanels.module \menu_minipanels_page_alter()
Implements hook_page_alter().
This function does two things: 1. Prepare the links. 2. Build the output. This probably means the module could be refactored.
File
- ./
menu_minipanels.module, line 476 - Allows an administrator to specify a minipanel to be associated with a Drupal menu item. When that menu item is hovered or clicked (as per config), the minipanel content will be shown using the qTip javascript library.
Code
function menu_minipanels_page_alter(&$page) {
// Optionally ignore certain pages.
if (menu_minipanels_excluded_path()) {
return;
}
// Add js + css
// The main qTip script file should be stored in sites/all/libraries/qtip.
$qtip_path = menu_minipanels_get_qtip_path();
// If the qTip script isn't found, no point in continuing.
if ($qtip_path === FALSE) {
return;
}
// Load each of the menus that are configured for menu_minipanels. It is safe
// to use menu_get_names() here as the data is cached, and it won't be
// possible that the shortcut sets have been accidentally added.
$load_requirements = FALSE;
$enabled_menus = array();
foreach (menu_get_names() as $menu) {
if (variable_get('menu_minipanels_' . $menu . '_enabled', FALSE)) {
$enabled_menus[] = $menu;
// Loop through each level of the menu tree and see whether qTip needs to
// be loaded.
$level = 0;
while ($items = menu_navigation_links($menu, $level)) {
if (menu_minipanels_prepare_links($items)) {
$load_requirements = TRUE;
}
$level++;
}
}
}
// If the main menu is enabled and the main & secondary menus both point to
// the same menu, load the second level of that menu.
$primary_menu = variable_get('menu_main_links_source', 'main-menu');
$secondary_menu = variable_get('menu_secondary_links_source', 'user-menu');
if (in_array($primary_menu, $enabled_menus) && $primary_menu == $secondary_menu) {
if (menu_minipanels_prepare_links(menu_navigation_links($primary_menu, 1))) {
$load_requirements = TRUE;
}
}
// If menus are actually needed, load the required scripts & CSS.
if ($load_requirements) {
// The path to this module.
$path = drupal_get_path('module', 'menu_minipanels');
// Load the module's custom CSS.
drupal_add_css($path . '/css/menu_minipanels.css');
// This module's custom JS.
drupal_add_js($path . '/js/menu_minipanels.js', array(
'scope' => 'footer',
'weight' => -100,
));
// Optional callbacks.
if (variable_get('menu_minipanels_default_callbacks', TRUE)) {
drupal_add_js($path . '/js/menu_minipanels.callbacks.js');
}
// Load the qTip script.
drupal_add_js($qtip_path, array(
'scope' => 'footer',
'weight' => -99,
));
// Load the output.
$page['page_bottom']['menu_minipanels'] = menu_minipanels_panels();
}
}