// Adjust the menu tree parameters based on the block's configuration.
$level =
$this->configuration
['level'
];
$depth =
$this->configuration
['depth'
];
$parameters->
setMinDepth($level);
// When the depth is configured to zero, there is no depth limit. When depth
// is non-zero, it indicates the number of levels that must be displayed.
// Hence this is a relative depth that we must convert to an actual
// (absolute) depth, that may never exceed the maximum depth.
if ($depth > 0
) { $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
];