如何隐藏编辑|查看标签? [英] How to hide Edit | View tabs?
问题描述
可以隐藏
编辑|查看
Edit | View
每个节点顶部的选项卡?
tabs on top of each node ?
在主题设置(全球和标准主题,但我找不到)的这个选项。
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()
,获取任务的链接标记 - < a href =http://api.drupal.org/api/function/theme_menu_local_task/6 =noreferrer>
theme_menu_local_task()
,其中获取任务的< li>
元素。
theme_menu_item_link()
, which gets the link markup for the tasktheme_menu_local_task()
, which gets the<li>
element for the task.
所以,你通过覆盖 theme_menu_item_link()
和<$,可以以非常强大的方式摆脱查看和编辑本地任务c $ c> 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>\n";
}
}
这样,你依靠菜单路由器路径,不修改菜单路由器项目,并通过对核心功能或主题进行最小更改来实现所需的结果。
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屋!