function menu_tree_build in Menu Block 7.3
Same name and namespace in other branches
- 6.2 menu_block.module \menu_tree_build()
- 7.2 menu_block.module \menu_tree_build()
Build a menu tree based on the provided configuration.
Parameters
array $config: An array of configuration options that specifies how to build the menu tree and its title.
- delta: (string) The menu_block's block delta.
- menu_name: (string) The machine name of the requested menu. Can also be set to MENU_TREE__CURRENT_PAGE_MENU to use the menu selected by the page.
- parent_mlid: (int) The mlid of the item that should root the tree. Use 0 to use the menu's root.
- title_link: (boolean) Specifies if the title should be rendered as a link or a simple string.
- admin_title: (string) An optional title to uniquely identify the block on the administer blocks page.
- level: (int) The starting level of the tree.
- follow: (string) Specifies if the starting level should follow the active menu item. Should be set to 0, 'active' or 'child'.
- depth: (int) The maximum depth the tree should contain, relative to the starting level.
- expanded: (boolean) Specifies if the entire tree be expanded or not.
- sort: (boolean) Specifies if the tree should be sorted with the active trail at the top of the tree.
Return value
array An associative array containing several pieces of data.
- content: The tree as a renderable array.
- subject: The title rendered as HTML.
- subject_array: The title as a renderable array.
3 calls to menu_tree_build()
- menu_block_block_view in ./
menu_block.module - Implements hook_block_view().
- menu_block_menu_tree_content_type_admin_info in plugins/
content_types/ menu_tree/ menu_tree.inc - Callback to provide administrative info (the preview in panels when building a panel).
- menu_block_menu_tree_content_type_render in plugins/
content_types/ menu_tree/ menu_tree.inc - Renders a menu_tree content type based on the delta supplied in the configuration.
File
- ./
menu_block.module, line 505 - Provides configurable blocks of menu items.
Code
function menu_tree_build(array &$config) {
// Retrieve the active menu item from the database.
if ($config['menu_name'] == MENU_TREE__CURRENT_PAGE_MENU) {
$config['menu_name'] = menu_block_get_current_page_menu();
$config['parent_mlid'] = 0;
// If no menu link was found, don't display the block.
if (empty($config['menu_name'])) {
return array(
'subject' => t('The menu selected by the page'),
'subject_array' => array(),
'content' => array(),
);
}
}
// Get the default block name.
drupal_static_reset('menu_block_set_title');
$menu_names = menu_block_get_all_menus();
menu_block_set_title($menu_names[$config['menu_name']]);
// Get the raw menu tree data.
$tree = menu_tree_block_data($config);
$title = menu_block_get_title($config['title_link']);
// Create a renderable tree.
$data = array();
$data['subject_array'] = $title;
$data['subject'] = drupal_render($title);
$data['content'] = array();
if (!empty($tree) && ($output = menu_block_tree_output($tree, $config))) {
$data['content']['#content'] = $output;
$data['content']['#theme'] = array(
'menu_block_wrapper__' . str_replace('-', '_', $config['delta']),
'menu_block_wrapper__' . str_replace('-', '_', $config['menu_name']),
'menu_block_wrapper',
);
$data['content']['#config'] = $config;
$data['content']['#delta'] = $config['delta'];
}
return $data;
}