--- slicedmenu_orig.module 2007-06-13 11:42:00.000000000 +0200 +++ slicedmenu.module 2008-04-21 17:36:54.000000000 +0200 @@ -46,6 +46,15 @@ function slicedmenu_admin() { $form = array(); $menu_options = menu_get_root_menus(); + $mid = variable_get('slicedmenu_config', 0); + $menu = menu_get_item($mid); + $tree = slicedmenu_get_tree($menu, array(), 0); + $max_depth = slicedmenu_get_depth($tree); + $depth_options[-1] = t('All'); + for ($i = 0; $i <= $max_depth; $i++) { + $depth_options[$i] = t('Level') . ' ' . $i; + } + $form['slicedmenu_config'] = array( '#type' => 'select', '#title' => t('Menu to slice into blocks'), @@ -53,6 +62,13 @@ function slicedmenu_admin() { '#options' => $menu_options, '#description' => t('The menu you select will be sliced into one block per level'), ); + $form['slicedmenu_depth'] = array( + '#type' => 'select', + '#title' => t('Slice until level'), + '#default_value' => variable_get('slicedmenu_depth', -1), + '#options' => $depth_options, + '#description' => t('From the selected level on, the menu will not be sliced any more. Ps: when you change the menu which has to be sliced, you\'ll have to click "save" before the number of levels gets adjusted.'), + ); menu_rebuild(); @@ -98,21 +114,21 @@ function slicedmenu_get_depth($tree) { * Implementation of hook_block(). */ function slicedmenu_block($op = 'list', $delta = 0) { - $mid = variable_get('slicedmenu_config', 0); $menu = menu_get_item($mid); - $tree = slicedmenu_get_tree($menu, array(), 0); $depth = slicedmenu_get_depth($tree); - if ($op == "list") { + $slice_depth = variable_get('slicedmenu_depth', -1); + if ($slice_depth != -1 && $slice_depth < $depth) { + $depth = $slice_depth; + } + for ($i = 0; $i <= $depth; $i++) { $block[$i]["info"] = t($menu['title'] ."_level_". $i); } - - return $block; - + return $block; } elseif ($op == "view") { for ($i = 0; $i <= $depth; $i++) { @@ -135,20 +151,16 @@ function slicedmenu_block($op = 'list', * The tree menu containing the level to generate. */ function slicedmenu_generate_level($level, $tree) { - $bool = false; - $menu_level = array(); $mid = variable_get('slicedmenu_config', 0); - - if ($level == 0) { - - return theme_slicedmenu_tree($mid); + $slice_depth = variable_get('slicedmenu_depth', -1); + $all_sub_items = ($slice_depth == $level); - } - else { + if ($level != 0) { $trail = _menu_get_active_trail_in_submenu($mid); - - return theme_slicedmenu_tree($trail[$level]); + $mid = $trail[$level]; } + + return theme('slicedmenu_tree', $mid, $all_sub_items); } /** @@ -166,21 +178,21 @@ function theme_slicedmenu_item($mid, $tr /** * Generate the HTML output for a menu tree. */ -function theme_slicedmenu_tree($pid = 1) { +function theme_slicedmenu_tree($pid = 1, $all_sub_items = FALSE) { $menu = menu_get_menu(); - $trail = _menu_get_active_trail(); - $output = ''; if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) { - $output = '
'; } - return $output; + return ''; } ?> \ No newline at end of file