Skip to content
Snippets Groups Projects
Commit 91915d25 authored by Brian Canini's avatar Brian Canini
Browse files

patch - menu_block: allowing 2nd level menu_block not limited to active parent

parent faa08fe7
No related branches found
No related tags found
No related merge requests found
...@@ -244,7 +244,8 @@ ...@@ -244,7 +244,8 @@
"2962965": "https://www.drupal.org/files/issues/2018-09-01/block-permissions-2962965-4.patch" "2962965": "https://www.drupal.org/files/issues/2018-09-01/block-permissions-2962965-4.patch"
}, },
"drupal/menu_block": { "drupal/menu_block": {
"2809699": "https://www.drupal.org/files/issues/2018-10-26/menu_block-label_configuration-2809699-82.patch" "2809699": "https://www.drupal.org/files/issues/2018-10-26/menu_block-label_configuration-2809699-82.patch",
"2811337": "https://www.drupal.org/files/issues/menu_block-2_level_menu_block_not_limited_to_active_parent-2811337-58.patch"
}, },
"drupal/entity_embed": { "drupal/entity_embed": {
"2881745": "https://www.drupal.org/files/issues/2018-12-04/2881745-22.patch" "2881745": "https://www.drupal.org/files/issues/2018-12-04/2881745-22.patch"
......
...@@ -4636,7 +4636,8 @@ ...@@ -4636,7 +4636,8 @@
} }
}, },
"patches_applied": { "patches_applied": {
"2809699": "https://www.drupal.org/files/issues/2018-10-26/menu_block-label_configuration-2809699-82.patch" "2809699": "https://www.drupal.org/files/issues/2018-10-26/menu_block-label_configuration-2809699-82.patch",
"2811337": "https://www.drupal.org/files/issues/menu_block-2_level_menu_block_not_limited_to_active_parent-2811337-58.patch"
} }
}, },
"installation-source": "dist", "installation-source": "dist",
......
...@@ -209,13 +209,36 @@ public function build() { ...@@ -209,13 +209,36 @@ public function build() {
if ($depth > 0) { if ($depth > 0) {
$parameters->setMaxDepth(min($level + $depth - 1, $this->menuTree->maxDepth())); $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 we're using a fixed parent item, we'll skip this step.
$fixed_parent_menu_link_id = str_replace($menu_name . ':', '', $parent);
if ($level > 1 && !$fixed_parent_menu_link_id) {
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) {
$max_depth = min($level - 1 + $depth - 1, $this->menuTree->maxDepth());
$parameters->setMaxDepth($max_depth);
}
}
else {
return array();
}
}
// If expandedParents is empty, the whole menu tree is built. // If expandedParents is empty, the whole menu tree is built.
if ($expand) { if ($expand) {
$parameters->expandedParents = array(); $parameters->expandedParents = array();
} }
// When a fixed parent item is set, root the menu tree at the given ID. // When a fixed parent item is set, root the menu tree at the given ID.
if ($menuLinkID = str_replace($menu_name . ':', '', $parent)) { if ($fixed_parent_menu_link_id) {
$parameters->setRoot($menuLinkID); $parameters->setRoot($fixed_parent_menu_link_id);
// If the starting level is 1, we always want the child links to appear, // If the starting level is 1, we always want the child links to appear,
// but the requested tree may be empty if the tree does not contain the // but the requested tree may be empty if the tree does not contain the
......
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