这可以通过将system_admin_menu_block_page 的'page callback' 添加到您的hook_menu 实现中来实现:
因此,假设您要创建如下结构:
- 自定义主菜单(除了结构、模块等其他项目外,还会出现在工具栏上)
钩子实现类似于:
function MODULE_menu() {
$items['admin/main'] = array(
'title' => 'Custom main menu',
'description' => 'Main menu item which should appear on the toolbar',
'position' => 'left',
'weight' => -100, // Less weight so that it will appear to the extreme left, before dashboard.
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
$items['admin/main/sub-menu-1'] = array(
'title' => 'Sub menu item 1',
'description' => 'Child of the menu appearing in toolbar.',
'page callback' => 'drupal_get_form',
'page arguments' => array('custom_form'),
'access arguments' => array('custom permission'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/main/sub-menu-2'] = array(
'title' => 'Sub menu item 2',
'description' => 'Child of the menu appearing in toolbar.',
'page callback' => 'custom_page_callback',
'access arguments' => array('custom permission'),
'type' => MENU_NORMAL_ITEM,
);
}
P.S - 启用模块或将此代码添加到 hook_menu 实现后,您必须刷新缓存,以便 Drupal 选择新的菜单结构。