From a4667504cf8d7b4c5d73cfb3f8fd91d83600f23c Mon Sep 17 00:00:00 2001 From: Kristiaan Van den Eynde Date: Thu, 21 Jun 2012 16:50:55 +0200 Subject: [PATCH] #1650684 by kristiaanvandeneynde: Allow showing of siblings at deepest levels. --- menu_block.admin.inc | 15 ++++++++++++++- menu_block.follow.inc | 6 ++++-- menu_block.install | 1 + menu_block.module | 12 +++++++----- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/menu_block.admin.inc b/menu_block.admin.inc index 98f3bbb..ac5f188 100644 --- a/menu_block.admin.inc +++ b/menu_block.admin.inc @@ -162,6 +162,7 @@ function menu_block_delete_submit($form, &$form_state) { variable_del("menu_block_{$delta}_admin_title"); variable_del("menu_block_{$delta}_parent"); variable_del("menu_block_{$delta}_level"); + variable_del("menu_block_{$delta}_show_deepest"); variable_del("menu_block_{$delta}_follow"); variable_del("menu_block_{$delta}_depth"); variable_del("menu_block_{$delta}_expanded"); @@ -394,6 +395,17 @@ function menu_block_configure_form($form, &$form_state) { ), ), ); + $form['show_deepest'] = array( + '#type' => 'checkbox', + '#title' => t('Show siblings of deepest level'), + '#default_value' => $config['show_deepest'], + '#description' => t("This will still show the menu block when the active item has no children, albeit populated with the active item's siblings."), + '#states' => array( + 'visible' => array( + ':input[name=follow_parent]' => array('value' => 'child'), + ), + ), + ); $form['depth'] = array( '#type' => 'select', '#title' => t('Maximum depth'), @@ -436,7 +448,7 @@ function menu_block_configure_form($form, &$form_state) { $form['menu-block-wrapper-close'] = array('#markup' => ''); // Set visibility of advanced options. - foreach (array('title_link', 'follow', 'follow_parent', 'expanded', 'sort', 'parent_mlid') as $key) { + foreach (array('title_link', 'follow', 'follow_parent', 'show_deepest', 'expanded', 'sort', 'parent_mlid') as $key) { $form[$key]['#states']['visible'][':input[name=display_options]'] = array('value' => 'advanced'); } if ($config['title_link'] || $follow || $config['expanded'] || $config['sort'] || $config['parent_mlid']) { @@ -488,6 +500,7 @@ function _menu_block_block_save($delta = '', $edit = array()) { variable_set("menu_block_{$delta}_admin_title", $edit['admin_title']); variable_set("menu_block_{$delta}_parent", $edit['parent']); variable_set("menu_block_{$delta}_level", $edit['level']); + variable_set("menu_block_{$delta}_show_deepest", $edit['show_deepest']); variable_set("menu_block_{$delta}_follow", $edit['follow']); variable_set("menu_block_{$delta}_depth", $edit['depth']); variable_set("menu_block_{$delta}_expanded", $edit['expanded']); diff --git a/menu_block.follow.inc b/menu_block.follow.inc index c9be251..2ae76d0 100644 --- a/menu_block.follow.inc +++ b/menu_block.follow.inc @@ -11,10 +11,12 @@ * array The menu tree to prune. * @param $level * string The level which the tree will be pruned to: 'active' or 'child'. + * @param $show_deepest + * bool Whether or not to show at the deepest level (i.e.: show siblings) * @return * void */ -function _menu_tree_prune_active_tree(&$tree, $level) { +function _menu_tree_prune_active_tree(&$tree, $level, $show_deepest) { do { $found_active_trail = FALSE; // Examine each element at this level for the active trail. @@ -48,7 +50,7 @@ function _menu_tree_prune_active_tree(&$tree, $level) { } // If the active menu item has no children, we're done. else { - if ($level == 'child') { + if ($level == 'child' && !$show_deepest) { $tree = array(); } break 2; diff --git a/menu_block.install b/menu_block.install index 8132465..23beefe 100644 --- a/menu_block.install +++ b/menu_block.install @@ -15,6 +15,7 @@ function menu_block_uninstall() { variable_del("menu_block_{$delta}_parent"); variable_del("menu_block_{$delta}_level"); variable_del("menu_block_{$delta}_follow"); + variable_del("menu_block_{$delta}_show_deepest"); variable_del("menu_block_{$delta}_depth"); variable_del("menu_block_{$delta}_expanded"); variable_del("menu_block_{$delta}_sort"); diff --git a/menu_block.module b/menu_block.module index 83cf0c9..f3af452 100644 --- a/menu_block.module +++ b/menu_block.module @@ -188,6 +188,7 @@ function menu_block_get_config($delta = NULL) { 'title_link' => 0, 'admin_title' => '', 'level' => 1, + 'show_deepest'=> 0, 'follow' => 0, 'depth' => 0, 'expanded' => 0, @@ -213,6 +214,7 @@ function menu_block_get_config($delta = NULL) { $config['admin_title'] = variable_get("menu_block_{$delta}_admin_title", $config['admin_title']); $config['level'] = variable_get("menu_block_{$delta}_level", $config['level']); $config['follow'] = variable_get("menu_block_{$delta}_follow", $config['follow']); + $config['show_deepest']= variable_get("menu_block_{$delta}_show_deepest",$config['show_deepest']); $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']); @@ -335,7 +337,7 @@ function menu_tree_build($config) { // Prune the tree to the active menu item. if ($config['follow']) { - menu_tree_prune_active_tree($tree, $config['follow']); + menu_tree_prune_active_tree($tree, $config); } // If the menu-item-based tree is not "expanded", trim the tree to the active path. @@ -570,14 +572,14 @@ function menu_tree_prune_tree(&$tree, $level, $parent_item = FALSE) { * * @param $tree * array The menu tree to prune. - * @param $level - * string The level which the tree will be pruned to: 'active' or 'child'. + * @param $config + * array The configuration for this menu. * @return * void */ -function menu_tree_prune_active_tree(&$tree, $level) { +function menu_tree_prune_active_tree(&$tree, $config) { module_load_include('inc', 'menu_block', 'menu_block.follow'); - _menu_tree_prune_active_tree($tree, $level); + _menu_tree_prune_active_tree($tree, $config['follow'], $config['show_deepest']); } /** -- 1.7.7.3