如何隐藏编辑 |查看标签? [英] How to hide Edit | View tabs?
问题描述
我可以隐藏吗
编辑 |查看
每个节点顶部的标签?
我在主题设置中搜索过这个选项(全局和标准主题,但我找不到).
I've searched for this option in theme settings (both global and standard theme but I couldn't find it).
我仍然希望我的客户能够编辑/管理内容,所以我不能只是删除它的权限.
I still want to be able my customer to edit / administer content, so I cannot just remove the permission for it.
谢谢
推荐答案
这确实是一个展示性的事情,而不是一个功能性的事情,因此应该在主题级别完成.
This really is a presentational thing, not a functionality thing, so it should be done at the theme level.
覆盖theme_menu_local_tasks()
的问题是你覆盖/拿斧头到整个本地任务显示,当你真的只想用手术刀进入那里以删除两个特定的本地任务时.所以,你需要更具体一些.
The problem with overriding theme_menu_local_tasks()
is that you override/take a hatchet to the entire local task display, when you really just want to get in there with a scalpel to remove two specific local tasks. So, you need to get a little more specific.
theme_menu_local_tasks()
获取当前页面的本地任务并将它们传递给 menu_local_tasks()
.这里用到了两个主题函数:
theme_menu_local_tasks()
gets the current page's local tasks and passes them to menu_local_tasks()
. Here, two theme functions are used:
theme_menu_item_link()
,得到任务的链接标记theme_menu_local_task()
,得到任务的元素.
因此,您可以通过覆盖 theme_menu_item_link()
和 以非常可靠的方式摆脱 View 和 Edit 本地任务>theme_menu_local_task()
包含您对它们的检查:
So, you can get rid of the View and Edit local tasks in a really robust way by overriding theme_menu_item_link()
and theme_menu_local_task()
to include your check for them:
function mytheme_menu_item_link($link) {
// Local tasks for view and edit nodes shouldn't be displayed.
if ($link['type'] & MENU_LOCAL_TASK && ($link['path'] === 'node/%/edit' || $link['path'] === 'node/%/view')) {
return '';
}
else {
if (empty($link['localized_options'])) {
$link['localized_options'] = array();
}
return l($link['title'], $link['href'], $link['localized_options']);
}
}
function mytheme_menu_local_task($link, $active = FALSE) {
// Don't return a <li> element if $link is empty
if ($link === '') {
return '';
}
else {
return '<li '. ($active ? 'class="active" ' : '') .'>'. $link ."</li>
";
}
}
通过这种方式,您依赖于菜单路由路径,而不是修改菜单路由项,并且只需对核心功能或主题进行最少的更改即可实现您想要的结果.
This way, you're relying on the menu router path, not modifying the menu router item, and achieving the result you want with minimal changes to core functionality or theming.
这篇关于如何隐藏编辑 |查看标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!