'menu', 'module' => 'navigate_menu', 'content' => navigate_add_widget_link(''), ), ); case 'delete': break; } } /** * Generate menu widget */ function navigate_menu_widget($wid) { $settings = navigate_widget_settings_get($wid); if (!$settings['mid']) { // Generate a list of possible parents. $inputs['menu'] = drupal_get_form('navigate_menu_form'); $inputs['load'] = navigate_callback_button(array( 'class' => 'navigate-menu-load', 'callback' => 'navigate_menu_load_menu', 'content' => '', 'help' => 'Click to load this menu.', )); } else { $inputs['menu'] = navigate_menu_output($wid); } $output = theme('navigate_menu_widget', $inputs, $wid); return $output; } function navigate_menu_form() { $item = menu_link_load(1); $options = menu_parent_options(menu_get_menus(), $item); $default = 'primary-links:0'; $form['menu'] = array( '#type' => 'select', '#title' => t('Parent item'), '#default_value' => $default, '#name' => 'menu', '#value' => $default, '#options' => $options, '#parents' => array(''), ); return $form; } /** * Theme menu widget */ function theme_navigate_menu_widget($inputs, $wid) { $inputs['load'] = isset($inputs['load']) ? $inputs['load'] : ''; $content['widget'] = ' '; $content['title'] = t('Menu'); return $content; } /** * Implementation of hook_perm(). */ function navigate_menu_perm() { return array("navigate_menu use"); } /** * Implementation of hook_navigate_widget_process(). */ function navigate_menu_navigate_widget_process($wid, $action) { switch ($action) { case 'load': echo navigate_menu_load(); break; } } /** * Output a rendered menu */ function navigate_menu_load() { $output = navigate_menu_output($_POST['wid']); return $output; } /** * Output the selected menu */ function navigate_menu_output($wid) { $settings = navigate_widget_settings_get($wid); if (isset($_POST['mid'])) { navigate_variable_set(array('value' => $_POST['mid'], 'name' => 'mid', 'wid' => $_POST['wid'])); $mid = $_POST['mid']; } elseif ($settings['mid']) { $mid = $settings['mid']; } if ($mid) { $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 .= '
  • '. $data['link']["title"] .''. _navigate_menu_tree($data) .'
  • '; } } return $output; } } /** * Helper function for navigate_menu_tree() */ function _navigate_menu_tree($data) { if ($data['below']) { $content = navigate_menu_tree($data['below']); if ($content != '') { return ''; } } } /** * Implementation of hook_navigate_help_page(). */ function navigate_menu_navigate_help_page() { $help['content'] = t('

    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_widget' => array( 'arguments' => array('inputs' => NULL, 'wid' => NULL), ), ); }