滚动
在 Drupal 7 管理菜单中添加“添加内容”链接
新的 toolbar 模块,当然看起来比 admin menu 更现代。不过,我更喜欢 admin menu,因为我可以添加任意数量的链接,并且它们都可以通过一次点击访问。
因此,我决定继续使用 admin menu。安装后却发现出现乱码问题……编码设置有误。
打开 .htaccess 文件,并在文件末尾添加以下一行:
AddDefaultCharset UTF-8
现在一切正常了,俄文字母显示正确。但是……“添加内容”的链接不见了,我们需要手动添加它。为此,需要创建一个自定义模块,并添加以下代码:
<?php
/**
* @file
* 向 Admin Menu 添加“Create Content”链接,并移除“Tasks”和“Index”。
*/
/**
* 实现 hook_admin_menu_output_alter()。
*
* 在 admin menu 中添加“Create content”顶级子菜单。
*/
function custom_admin_menu_output_alter(&$content) {
// 为“Create content”菜单添加一个顶级项。
$content['create_content_links'] = array(
'#theme' => 'admin_menu_links',
'#weight' => -99,
'#sorted' => TRUE,
);
// 将“创建内容”子菜单添加到后台菜单中。
$content['create_content_links']['create-content'] = array(
'#title' => t('Create'),
'#href' => 'node/add',
'#weight' => -10,
);
foreach(node_type_get_types() as $type => $object) {
if (node_access('create', $type)) {
$node_type_url = str_replace('_', '-', $type);
$content['create_content_links']['create-content'][$node_type_url] = array(
'#title' => $object->name,
'#href' => 'node/add/'. $node_type_url,
);
} // end if node_access
} // end foreach
// 从 Admin Menu 中移除“Tasks”和“Index”
$admin_menu_exclusions = array(
t('Tasks'),
t('Index'),
);
foreach($content['menu'] as $menu_key => $menu_tree) {
if (in_array($menu_tree['#title'], $admin_menu_exclusions))
unset($content['menu'][$menu_key]);
}
} // end hook_admin_menu_output_alter
经过这些简单的修改后,我们就能看到一个我更喜欢的 admin menu。至于 toolbar 模块,可以直接禁用。