'view'))) { navigate_add_js('jquery.treeview.js'); navigate_add_js('navigate_menu.js'); navigate_add_css('navigate_menu.css', 'navigate_menu'); navigate_add_css('jquery.treeview.css', 'navigate_menu'); } } /** * Implementation of hook_navigate_ajax(). */ function navigate_menu_navigate_ajax($op, $data) { switch ($op) { case 'loadMenu': global $_navigate, $user; $_navigate['users'][$user->uid]['widgets'][$data['wid']]['title'] = $data['title']; $_navigate['users'][$user->uid]['widgets'][$data['wid']]['plugin']['settings']['menu_mid'] = $data['mid']; navigate_user_save($user->uid); navigate_json(array( 'wid' => $data['wid'], 'content' => navigate_menu_output($data['mid'], $data['wid']), )); break; case 'widget_add': if ($widget = navigate_widget_add('navigate_menu')) { navigate_json(array( 'wid' => $widget['wid'], 'content' => navigate_output_widget($widget), )); } else { navigate_json(array( 'wid' => 0, 'data' => array('error' => 'Unable to create Menu widget.'), )); } break; } } /** * Implementation of hook_navigate_libraries(). */ function navigate_menu_navigate_libraries($path = FALSE) { if ($path) { return array( drupal_get_path('module', 'navigate_menu'), ); } else { return array( 'navigate_menu.js' => array(), 'jquery.treeview.js' => array( 'title' => 'jQuery Treeview', 'vendor url' => 'https://github.com/jzaefferer/jquery-treeview', 'download url' => 'https://github.com/jzaefferer/jquery-treeview/raw/master/jquery.treeview.js', ), ); } } /** * 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 'name': return 'Plugin: Menu'; break; case 'display': if (!$widget) { return array(); } $mid = $widget['plugin']['settings']['menu_mid']; if (!$mid) { return array(); } // 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' => base_path() . 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', // Default title of the widget 'weight' => 0, // Default widget weight 'plugin' => array( 'name' => 'navigate_menu', // Name of the plugin 'user_default' => TRUE, // Include this plugin as a default widget if new user 'settings' => array( // Specific plugin settings '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))); }