diff --git a/menu_block.admin.inc b/menu_block.admin.inc
index eda4fd6..a41920a 100644
--- a/menu_block.admin.inc
+++ b/menu_block.admin.inc
@@ -382,6 +382,13 @@ function menu_block_configure_form($form, &$form_state) {
'#default_value' => $config['sort'],
'#description' => t('Sort each item in the active trail to the top of its level. When used on a deep or wide menu tree, the active menu item’s children will be easier to see when the page is reloaded.'),
);
+ $form['hide_siblings'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Hide siblings of the active menu item’s trail.'),
+ '#default_value' => $config['hide_siblings'],
+ '#description' => t('If a menu item isn\'t in the active trail, don\'t show it.'),
+ );
+
$form['parent'] = array(
'#type' => 'select',
'#title' => t('Fixed parent item'),
@@ -398,7 +405,7 @@ function menu_block_configure_form($form, &$form_state) {
foreach (array('title_link', 'follow', 'depth_relative', 'follow_parent', 'expanded', 'sort', 'parent') 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']) {
+ if ($config['title_link'] || $follow || $config['expanded'] || $config['sort'] || $config['hide_siblings'] || $config['parent_mlid']) {
$form['display_options']['#default_value'] = 'advanced';
}
@@ -447,6 +454,7 @@ function _menu_block_block_save($delta = '', $edit = array()) {
variable_set("menu_block_{$delta}_depth_relative", $edit['depth_relative']);
variable_set("menu_block_{$delta}_expanded", $edit['expanded']);
variable_set("menu_block_{$delta}_sort", $edit['sort']);
+ variable_set("menu_block_{$delta}_hide_siblings", $edit['hide_siblings']);
}
}
}
diff --git a/menu_block.module b/menu_block.module
index a5bf396..0c04215 100644
--- a/menu_block.module
+++ b/menu_block.module
@@ -245,6 +245,8 @@ function menu_block_default_config() {
'depth_relative' => 0,
'expanded' => 0,
'sort' => 0,
+ 'hide_siblings' => 0,
+ 'active_depth' => array(),
);
}
@@ -412,6 +414,12 @@ function menu_tree_block_data(array &$config) {
menu_tree_sort_active_path($tree);
}
+ // When hiding siblings, sort the active path & set the initial active depth.
+ if ($config['hide_siblings']) {
+ menu_tree_sort_active_path($tree);
+ $config['active_depth'][0] = 1;
+ }
+
return $tree;
}
@@ -802,6 +810,30 @@ function menu_block_tree_output(array &$tree, array $config = array()) {
$hook_delta = str_replace('-', '_', $config['delta']);
$hook_menu_name = str_replace('-', '_', $config['menu_name']);
+ //
+ // First, loop through the tree to get the depth of the current active item.
+ // If we don't do this, the depth of the current item won't be detected until
+ // we see the active item, which means lighter menu items never hide.
+ foreach ($tree as $key => $value) {
+ if ($config['hide_siblings']) {
+ // Build array of the active trails depth.
+ if (!empty($tree[$key]['link']['in_active_trail']) && $tree[$key]['link']['depth'] > 1) {
+ $config['active_depth'][] = $tree[$key]['link']['depth'];
+ }
+ }
+ }
+ // Loop through the tree and add a 'hidden' attribute to all non-active
+ // items at the same depth as the currently active menu item.
+ foreach ($tree as $key => $value) {
+ if ($config['hide_siblings']) {
+ // Hide menu items on the same depth but that are not in the active trail ie. active trail siblings.
+ if ( in_array($tree[$key]['link']['depth'], $config['active_depth']) && $tree[$key]['link']['in_active_trail'] == FALSE) {
+ $tree[$key]['link']['hidden'] = 1;
+ }
+ }
+ }
+
+ // Render all links that aren't hidden.
// Pull out just the menu links we are going to render so that we
// get an accurate count for the first/last classes.
foreach ($tree as $key => &$value) {
diff --git a/menu_block_export.admin.inc b/menu_block_export.admin.inc
index 8e487b8..8269ca8 100644
--- a/menu_block_export.admin.inc
+++ b/menu_block_export.admin.inc
@@ -83,6 +83,7 @@ function menu_block_export_form_submit(&$form, &$form_state) {
'depth' => {$config['depth']},
'expanded' => {$config['expanded']},
'sort' => {$config['sort']},
+ 'hide_siblings' => {$config['hide_siblings']},
),
END_OF_CONFIG;
}
diff --git a/menu_block.admin.inc b/menu_block.admin.inc
index eda4fd6..22098e2 100644
--- a/menu_block.admin.inc
+++ b/menu_block.admin.inc
@@ -382,6 +382,12 @@ function menu_block_configure_form($form, &$form_state) {
'#default_value' => $config['sort'],
'#description' => t('Sort each item in the active trail to the top of its level. When used on a deep or wide menu tree, the active menu item’s children will be easier to see when the page is reloaded.'),
);
+ $form['hide_siblings'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Hide siblings of the active menu item’s trail.'),
+ '#default_value' => $config['hide_siblings'],
+ '#description' => t('If a menu item isn\'t in the active trail, don\'t show it.'),
+ );
$form['parent'] = array(
'#type' => 'select',
'#title' => t('Fixed parent item'),
@@ -395,10 +401,10 @@ 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', 'depth_relative', 'follow_parent', 'expanded', 'sort', 'parent') as $key) {
+ foreach (array('title_link', 'follow', 'depth_relative', 'follow_parent', 'expanded', 'sort', 'parent','hide_siblings') 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']) {
+ if ($config['title_link'] || $follow || $config['expanded'] || $config['sort'] || $config['hide_siblings'] || $config['parent_mlid']) {
$form['display_options']['#default_value'] = 'advanced';
}
@@ -447,6 +453,7 @@ function _menu_block_block_save($delta = '', $edit = array()) {
variable_set("menu_block_{$delta}_depth_relative", $edit['depth_relative']);
variable_set("menu_block_{$delta}_expanded", $edit['expanded']);
variable_set("menu_block_{$delta}_sort", $edit['sort']);
+ variable_set("menu_block_{$delta}_hide_siblings", $edit['hide_siblings']);
}
}
}
diff --git a/menu_block.module b/menu_block.module
index a5bf396..0c04215 100644
--- a/menu_block.module
+++ b/menu_block.module
@@ -245,6 +245,8 @@ function menu_block_default_config() {
'depth_relative' => 0,
'expanded' => 0,
'sort' => 0,
+ 'hide_siblings' => 0,
+ 'active_depth' => array(),
);
}
@@ -412,6 +414,12 @@ function menu_tree_block_data(array &$config) {
menu_tree_sort_active_path($tree);
}
+ // When hiding siblings, sort the active path & set the initial active depth.
+ if ($config['hide_siblings']) {
+ menu_tree_sort_active_path($tree);
+ $config['active_depth'][0] = 1;
+ }
+
return $tree;
}
@@ -802,6 +810,30 @@ function menu_block_tree_output(array &$tree, array $config = array()) {
$hook_delta = str_replace('-', '_', $config['delta']);
$hook_menu_name = str_replace('-', '_', $config['menu_name']);
+ //
+ // First, loop through the tree to get the depth of the current active item.
+ // If we don't do this, the depth of the current item won't be detected until
+ // we see the active item, which means lighter menu items never hide.
+ foreach ($tree as $key => $value) {
+ if ($config['hide_siblings']) {
+ // Build array of the active trails depth.
+ if (!empty($tree[$key]['link']['in_active_trail']) && $tree[$key]['link']['depth'] > 1) {
+ $config['active_depth'][] = $tree[$key]['link']['depth'];
+ }
+ }
+ }
+ // Loop through the tree and add a 'hidden' attribute to all non-active
+ // items at the same depth as the currently active menu item.
+ foreach ($tree as $key => $value) {
+ if ($config['hide_siblings']) {
+ // Hide menu items on the same depth but that are not in the active trail ie. active trail siblings.
+ if ( in_array($tree[$key]['link']['depth'], $config['active_depth']) && $tree[$key]['link']['in_active_trail'] == FALSE) {
+ $tree[$key]['link']['hidden'] = 1;
+ }
+ }
+ }
+
+ // Render all links that aren't hidden.
// Pull out just the menu links we are going to render so that we
// get an accurate count for the first/last classes.
foreach ($tree as $key => &$value) {
diff --git a/menu_block_export.admin.inc b/menu_block_export.admin.inc
index 8e487b8..8269ca8 100644
--- a/menu_block_export.admin.inc
+++ b/menu_block_export.admin.inc
@@ -83,6 +83,7 @@ function menu_block_export_form_submit(&$form, &$form_state) {
'depth' => {$config['depth']},
'expanded' => {$config['expanded']},
'sort' => {$config['sort']},
+ 'hide_siblings' => {$config['hide_siblings']},
),
END_OF_CONFIG;
}