Skip to content
Snippets Groups Projects
Commit 6eb59c81 authored by catch's avatar catch
Browse files

Issue #2631468 by snufkin, johnmcc, DamienMcKenna, aaronbauman, kiwad,...

Issue #2631468 by snufkin, johnmcc, DamienMcKenna, aaronbauman, kiwad, acrosman, esolitos, Tom Robert, Yogesh Pawar, acke: Menu subtrees in menu blocks show all subitems regardless of the active menu item
parent 06848b26
No related branches found
No related tags found
No related merge requests found
......@@ -135,6 +135,25 @@ public function build() {
$parameters->setMaxDepth(min($level + $depth - 1, $this->menuTree->maxDepth()));
}
// For menu blocks with start level greater than 1, only show menu items
// from the current active trail. Adjust the root according to the current
// position in the menu in order to determine if we can show the subtree.
if ($level > 1) {
if (count($parameters->activeTrail) >= $level) {
// Active trail array is child-first. Reverse it, and pull the new menu
// root based on the parent of the configured start level.
$menu_trail_ids = array_reverse(array_values($parameters->activeTrail));
$menu_root = $menu_trail_ids[$level - 1];
$parameters->setRoot($menu_root)->setMinDepth(1);
if ($depth > 0) {
$parameters->setMaxDepth(min($level - 1 + $depth - 1, $this->menuTree->maxDepth()));
}
}
else {
return [];
}
}
$tree = $this->menuTree->load($menu_name, $parameters);
$manipulators = [
['callable' => 'menu.default_tree_manipulators:checkAccess'],
......
......@@ -218,9 +218,7 @@ public function testConfigLevelDepth() {
'test.example6' => [],
'test.example8' => [],
];
$no_active_trail_expectations['level_2_only'] = [
'test.example7' => [],
];
$no_active_trail_expectations['level_2_only'] = [];
$no_active_trail_expectations['level_3_only'] = [];
$no_active_trail_expectations['level_1_and_beyond'] = $no_active_trail_expectations['all'];
$no_active_trail_expectations['level_2_and_beyond'] = $no_active_trail_expectations['level_2_only'];
......@@ -266,7 +264,6 @@ public function testConfigLevelDepth() {
];
$active_trail_expectations['level_2_only'] = [
'test.example3' => [],
'test.example7' => [],
];
$active_trail_expectations['level_3_only'] = [
'test.example4' => [],
......@@ -276,7 +273,6 @@ public function testConfigLevelDepth() {
'test.example3' => [
'test.example4' => [],
],
'test.example7' => [],
];
$active_trail_expectations['level_3_and_beyond'] = $active_trail_expectations['level_3_only'];
foreach ($blocks as $id => $block) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment