diff --git a/site_map.admin.inc b/site_map.admin.inc index 98c97aa..66b8876 100644 --- a/site_map.admin.inc +++ b/site_map.admin.inc @@ -88,6 +88,41 @@ function site_map_admin_settings_form() { '#default_value' => variable_get('site_map_show_menus_hidden', 0), '#description' => t('When enabled, hidden menu links will also be shown.'), ); + + // Add in menu ordering options. + $menu_option_count = count($menu_options); + + $form['site_map_content']['menu_order'] = array( + '#type' => 'fieldset', + '#title' => t('Display order of menu links (weight)'), + '#description' => t('@first is highest and will be displayed first, with @last being displayed last.
NOTE: This only applies to enabled menus (above). Where numerical order is not defined, alphabetical ordering will be applied.', array( + '@first' => '1', + '@last' => $menu_option_count, + )), + ); + + $default_select = t('Select'); + $menu_order = array($default_select); + + for ($i = 0; $i < $menu_option_count; $i++) { + $order_index = $i + 1; + $menu_order[$order_index] = $order_index; + } + + foreach ($menu_options as $menu_opt_key => $menu_opt_value) { + $safe_menu_title = strtolower(str_replace('-', '_', $menu_opt_key)); + $safe_menu_title = 'site_map_menu_order_' . $safe_menu_title; + + $form['site_map_content']['menu_order'][$safe_menu_title]= array( + '#type' => 'select', + '#title' => t($menu_opt_value), + '#title_display' => 'after', + '#default_value' => variable_get($safe_menu_title, array(0)), + '#options' => $menu_order, + '#multiple' => FALSE, + ); + } + if (module_exists('faq')) { $form['site_map_content']['site_map_show_faq'] = array( '#type' => 'checkbox', diff --git a/site_map.module b/site_map.module index e63fbb8..05630f1 100644 --- a/site_map.module +++ b/site_map.module @@ -394,30 +394,60 @@ function _site_map_menus() { $output = ''; $class = array(); $options = array(); - $mids = array_filter(variable_get('site_map_show_menus', array())); - - if (!empty($mids)) { - foreach ($mids as $mid) { - $menu = menu_load($mid); - // Use menu_tree_all_data to retrieve the expanded tree. - $tree = menu_tree_all_data($mid); - if (module_exists('i18n_menu')) { - $tree = i18n_menu_localize_tree($tree, $GLOBALS['language']->language); + $menus = variable_get('site_map_show_menus', array()); + $menu_order = array(); + $sorted_menu = array(); + + // Load weight settings for each menu, + // also remove any disabled menus. + foreach ($menus as $mid => $menu) { + if (!empty($menu)) { + $safe_menu_title = strtolower(str_replace('-', '_', $mid)); + $safe_menu_title = 'site_map_menu_order_' . $safe_menu_title; + $order = variable_get($safe_menu_title, array()); + + if (!empty($order)) { + $menu_order[$order] = $mid; } - $menu_display = _site_map_menu_tree_output($tree); - $menu_html = drupal_render($menu_display); - if (!empty($menu_html)) { - $title = t($menu['title']); - if (module_exists('i18n_string')) { - $title = i18n_string_plain(array('menu', 'menu', $menu['menu_name'], 'title'), $title); - } - _site_map_set_option($options, 'site_map_show_titles', 1, 1, 'show_titles', TRUE); + } + else { + unset($menus[$mid]); + } + } - $class[] = 'site-map-box-menu'; - $class[] = 'site-map-box-menu-' . $mid; - $attributes = array('class' => $class); - $output .= theme('site_map_box', array('title' => $title, 'content' => $menu_html, 'attributes' => $attributes, 'options' => $options)); + if (!empty($menu_order)) { + // Sort the menu orders. + ksort($menu_order); + + // Find and add the sorted menus. + foreach ($menu_order as $order => $mid) { + $sorted_menu[$mid] = $menus[$mid]; + } + } + + // Finally, tack on any menus that don't have sorting enabled. + $sorted_menu += $menus; + + foreach ($sorted_menu as $mid) { + $menu = menu_load($mid); + // Use menu_tree_all_data to retrieve the expanded tree. + $tree = menu_tree_all_data($mid); + if (module_exists('i18n_menu')) { + $tree = i18n_menu_localize_tree($tree, $GLOBALS['language']->language); + } + $menu_display = _site_map_menu_tree_output($tree); + $menu_html = drupal_render($menu_display); + if (!empty($menu_html)) { + $title = t($menu['title']); + if (module_exists('i18n_string')) { + $title = i18n_string_plain(array('menu', 'menu', $menu['menu_name'], 'title'), $title); } + _site_map_set_option($options, 'site_map_show_titles', 1, 1, 'show_titles', TRUE); + + $class[] = 'site-map-box-menu'; + $class[] = 'site-map-box-menu-' . $mid; + $attributes = array('class' => $class); + $output .= theme('site_map_box', array('title' => $title, 'content' => $menu_html, 'attributes' => $attributes, 'options' => $options)); } }