diff --git a/sites/all/modules/menu_block/menu_block.admin.inc b/sites/all/modules/menu_block/menu_block.admin.inc index 88d1beb..f779a37 100644 --- a/sites/all/modules/menu_block/menu_block.admin.inc +++ b/sites/all/modules/menu_block/menu_block.admin.inc @@ -246,6 +246,12 @@ function menu_block_configure_form(&$form_state) { ), '#description' => t('Blocks that start with the 1st level will always be visible. Blocks that start with the 2nd level or deeper will only be visible when the trail to the active menu item is in the block’s tree.'), ); + $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?'), + ); // The value of "follow" in the database/config array is either FALSE or the // value of the "follow_parent" form element. if ($follow = $config['follow']) { @@ -356,6 +362,7 @@ function _menu_block_block_save($delta, $edit) { 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/sites/all/modules/menu_block/menu_block.module b/sites/all/modules/menu_block/menu_block.module index 2dc1e9b..db9193b 100644 --- a/sites/all/modules/menu_block/menu_block.module +++ b/sites/all/modules/menu_block/menu_block.module @@ -180,6 +180,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, @@ -196,6 +197,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'])); } @@ -317,10 +319,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']); } } @@ -505,7 +507,8 @@ 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++) { @@ -516,8 +519,12 @@ function menu_tree_prune_tree(&$tree, $level, $parent_item = FALSE) { 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(); $found_active_trail = TRUE; + if (!empty($include_parent)) { + $tree = array($key=>$tree[$key]); + } else { + $tree = $tree[$key]['below'] ? $tree[$key]['below'] : array(); + } break; } } @@ -538,8 +545,12 @@ function menu_tree_prune_tree(&$tree, $level, $parent_item = FALSE) { // 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(); $found_active_trail = TRUE; + if (!empty($include_parent)) { + $tree = array($key=>$tree[$key]); + } else { + $tree = $tree[$key]['below'] ? $tree[$key]['below'] : array(); + } break; } }