$data['wid'], 'content' => navigate_menu_output($data['mid'], $data['wid']), )); break; } } /** * Implementation of hook_navigate_permissions(). */ function navigate_menu_navigate_permissions() { return array( 'navigate_menu' => array( '#title' => 'Menu', 'view', ) ); } /** * Implementation of hook_navigate_plugin(). */ function navigate_menu_navigate_plugin($op, $widget = NULL) { switch ($op) { case 'display': $mid = navigate_variable_get('menu_mid', FALSE, $widget['wid']); // Use the name of the menu as the title if a custom set title doesn't exist if (empty($widget['title'])) { $widget['title'] = navigate_menu_get_title($mid); } return array( // Content to display for a widget with this plugin type 'content' => navigate_menu_output($mid, $widget['wid']), // Settings to display for a widget with this plugin type. 'settings' => array( // To create a new tab in the widget's settings, use a unique name (preferably the plugin name). // Otherwise if exists, only the content will be used and appended to content that already exists. 'navigate_menu' => array( 'title' => 'Menu', 'description' => 'Modify this widget\'s menu settings', 'content' => navigate_menu_form($mid) . navigate_callback_button(array( 'callback' => 'loadMenu', 'id' => 'load-menu', 'plugin' => 'navigate_menu', 'tooltip' => 'Click to load this menu.', 'value' => t('Load'), 'wid' => $widget['wid'], )), ), ), ); break; case 'delete': break; // Create an add widget link in the settings dialog case 'widget_add': return array( 'plugin' => 'navigate_menu', 'name' => 'Menu', 'icon' => '/' . drupal_get_path('module', 'navigate_menu') . '/icon.png', 'single' => FALSE, ); break; // Include this default widget when a user does not have any to display case 'widget_default': return array( 'title' => 'Navigation', 'weight' => 0, 'plugin' => array( 'type' => 'navigate_menu', 'settings' => array( 'menu_mid' => 'navigation:0', ), ), ); break; // Return an empty array otherwise default: return array(); break; } } function navigate_menu_get_title($mid) { $menu = explode(':', $mid); $title = db_result(db_query("SELECT link_title FROM {menu_links} WHERE menu_name='" . $menu[0] . "' AND mlid='" . $menu[1] . "'")); if ($menu[1] == 0) { $title = ucwords(str_replace("-", " ", $menu[0])); } return $title; } function navigate_menu_form($mid = 'primary-links:0') { $item = menu_link_load(1); $options = menu_parent_options(menu_get_menus(), $item); $form['menu'] = array( '#type' => 'select', '#title' => t('Parent item'), '#default_value' => $mid, '#name' => 'menu', '#value' => $mid, '#options' => $options, '#parents' => array(''), ); return drupal_render($form); } /** * Output the selected menu */ function navigate_menu_output($mid, $wid) { $output = ''; if (!empty($mid)) { $output = navigate_menu_tree($mid); } return theme('navigate_menu_output', $output, $wid); } /** * Theme menu widget */ function theme_navigate_menu_output($output, $wid) { $output = '
'; return $output; } /** * Part of a series of functions to generate a specific menu tree * * Please note, this is a total hack. There must be a better way. Basically, * this recurses through the entire menu, trying to find one that has the * selected mlid in it. If it does, it returns that sub-array. */ function navigate_menu_sub_tree($data='', $menu_id='') { static $id; static $return; if ($menu_id != '') { $id = $menu_id; } if (!is_array($data)) { $data = menu_tree_all_data(); } foreach ($data as $key => $sub_data) { $data['link']["hidden"] = isset($data['link']["hidden"]) ? $data['link']["hidden"] : NULL; if ($data['link']["hidden"] == 0) { $key_parts = explode(' ', $key); if (end($key_parts) == $id) { $return = $sub_data; break; } _navigate_menu_sub_tree($sub_data); } } return $return['below']; } /** * Helper function for navigate_menu_sub_tree() */ function _navigate_menu_sub_tree($data) { if ($data['below']) { $content = navigate_menu_sub_tree($data['below']); } } /** * Renders a menu in list format */ function navigate_menu_tree($data) { $output = ''; if (is_string($data)) { $nav_array = explode(':', $data); if ($nav_array[1] > 0) { $data = navigate_menu_sub_tree('', $nav_array[1]); } else { $data = menu_tree_all_data($nav_array[0]); } } if (is_array($data)) { foreach ($data as $key => $data) { if ($data['link']["hidden"] == 0) { $output .= 'The Menu widget allows you add an expandable menu widget to your Navigate bar. After adding a Menu widget, you willl see a select box with a menu listing. Select the menu you would like to load and click the "Load" button to load it into the widget. Once a menu is loaded, there are no additional settings.
'); $help['title'] = 'Menu'; $help['access'] = user_access('navigate_menu use'); return $help; } /** * Implementation of hook_theme(). */ function navigate_menu_theme() { return array('navigate_menu_output' => array('arguments' => array('output' => NULL, 'wid' => NULL))); }