diff --git a/menu_block.admin.inc b/menu_block.admin.inc index 2717b45..df83b72 100644 --- a/menu_block.admin.inc +++ b/menu_block.admin.inc @@ -411,6 +411,12 @@ function menu_block_configure_form($form, &$form_state) { ), ), ); + $form['include_parent'] = array( + '#type' => 'checkbox', + '#title' => t('Include Parent'), + '#default_value' => $config['include_parent'], + '#description' => t('Should this block include the parent as the starting level?'), + ); $form['depth'] = array( '#type' => 'select', '#title' => t('Maximum depth'), @@ -501,6 +507,7 @@ function _menu_block_block_save($delta = '', $edit = array()) { variable_set("menu_block_{$delta}_title_link", $edit['title_link']); variable_set("menu_block_{$delta}_admin_title", $edit['admin_title']); variable_set("menu_block_{$delta}_parent", $edit['parent']); + variable_set("menu_block_{$delta}_include_parent", $edit['include_parent']); variable_set("menu_block_{$delta}_level", $edit['level']); variable_set("menu_block_{$delta}_follow", $edit['follow']); variable_set("menu_block_{$delta}_depth", $edit['depth']); diff --git a/menu_block.module b/menu_block.module index 951db07..400ecee 100644 --- a/menu_block.module +++ b/menu_block.module @@ -139,6 +139,7 @@ function menu_block_get_config($delta = NULL) { 'parent_mlid' => 0, 'title_link' => 0, 'admin_title' => '', + 'include_parent' => 0, 'level' => 1, 'follow' => 0, 'depth' => 0, @@ -155,6 +156,7 @@ function menu_block_get_config($delta = NULL) { $config['depth'] = variable_get("menu_block_{$delta}_depth", $config['depth']); $config['expanded'] = variable_get("menu_block_{$delta}_expanded", $config['expanded']); $config['sort'] = variable_get("menu_block_{$delta}_sort", $config['sort']); + $config['include_parent'] = variable_get("menu_block_{$delta}_include_parent", $config['include_parent']); list($config['menu_name'], $config['parent_mlid']) = explode(':', variable_get("menu_block_{$delta}_parent", $config['menu_name'] . ':' . $config['parent_mlid'])); } @@ -265,10 +267,10 @@ function menu_tree_build($config) { if ($config['level'] > 1 || $config['parent_mlid']) { if ($config['parent_mlid']) { $parent_item = menu_link_load($config['parent_mlid']); - menu_tree_prune_tree($tree, $config['level'], $parent_item); + menu_tree_prune_tree($tree, $config['level'], $parent_item, $config['include_parent']); } else { - menu_tree_prune_tree($tree, $config['level']); + menu_tree_prune_tree($tree, $config['level'], false, $config['include_parent']); } } @@ -458,7 +460,7 @@ function menu_tree_sort_active_path(&$tree) { * @return * void */ -function menu_tree_prune_tree(&$tree, $level, $parent_item = FALSE) { +function menu_tree_prune_tree(&$tree, $level, $parent_item = FALSE, $include_parent = FALSE) { if (!empty($parent_item)) { // Prune the tree along the path to the menu item. for ($i = 1; $i <= MENU_MAX_DEPTH && $parent_item["p$i"] != '0'; $i++) { @@ -468,8 +470,12 @@ function menu_tree_prune_tree(&$tree, $level, $parent_item = FALSE) { foreach ($tree AS $key => &$value) { if ($tree[$key]['link']['mlid'] == $plid) { menu_block_set_title($tree[$key]['link']); - // Prune the tree to the children of this ancestor. - $tree = $tree[$key]['below'] ? $tree[$key]['below'] : array(); + // Prune the tree to the children of this ancestor, unless configured to include the parent + if (!empty($include_parent)) { + $tree = array($key=>$tree[$key]); + } else { + $tree = $tree[$key]['below'] ? $tree[$key]['below'] : array(); + } $found_active_trail = TRUE; break; } @@ -490,8 +496,12 @@ function menu_tree_prune_tree(&$tree, $level, $parent_item = FALSE) { if ($tree[$key]['link']['in_active_trail']) { // Get the title for the pruned tree. menu_block_set_title($tree[$key]['link']); - // Prune the tree to the children of the item in the active trail. - $tree = $tree[$key]['below'] ? $tree[$key]['below'] : array(); + // Prune the tree to the children of the item in the active trail, unless configured to include the parent + if (!empty($include_parent)) { + $tree = array($key=>$tree[$key]); + } else { + $tree = $tree[$key]['below'] ? $tree[$key]['below'] : array(); + } $found_active_trail = TRUE; break; }