1 system.menu.inc | system_menu_tree_block_data(array &$config) |
Gets the data structure representing a menu tree for the given configuration.
Parameters
array $config: See the $config param of menu_tree_build().
Return value
array:
File
- core/
modules/ system/ system.menu.inc, line 306 - Menu block configuration form and display.
Code
function system_menu_tree_block_data(array &$config) {
// @todo: Anything that makes adjustments based on style should come from
// a menu style plugin.
// See https://github.com/backdrop/backdrop-issues/issues/1457
if ($config['style'] === 'top_only') {
$config['level'] = 1;
$config['depth'] = 1;
}
elseif ($config['style'] === 'dropdown') {
$config['level'] = 1;
}
// Determine the max depth based on level and depth setting.
$max_depth = ($config['depth'] == 0) ? NULL : min($config['level'] + $config['depth'] - 1, MENU_MAX_DEPTH);
// Set the expand all flag if the style requires it.
$expand_all = FALSE;
if ($config['depth'] != 1) {
if (isset($config['expand_all'])) {
$expand_all = (bool) $config['expand_all'];
}
// Right now we assume if any style is set, the whole menu should be expanded.
elseif ($config['style'] !== 'tree') {
$expand_all = TRUE;
}
}
// Get the menu tree based on the configuration options using the central
// menu system cache.
$tree = menu_tree_page_data($config['menu_name'], $max_depth, FALSE, $expand_all);
// Allow alteration of the tree and config before we begin operations on it.
backdrop_alter('menu_block_tree', $tree, $config);
// Prune the tree along the active trail to the specified level.
if ($config['level'] > 1) {
system_menu_tree_prune_tree($tree, $config['level']);
}
// Trim the tree to the active path.
if (!$expand_all) {
system_menu_tree_trim_active_path($tree);
}
// Trim the branches that extend beyond the specified depth.
if ($config['depth'] > 0) {
system_menu_tree_depth_trim($tree, $config['depth']);
}
return $tree;
}