[英]Change tab names in Drupal module depending on the user Logged In.
Working on Intranet built on Drupal where I got a module with couple of tabs. 在基于Drupal的Intranet上工作,在那里我得到了带有几个标签的模块。
There are two types of users, admin and non-admins. 有两种类型的用户,管理员和非管理员。 I like to change the name of the tab depending on who is viewing it.
我喜欢根据查看者更改标签的名称。
Currently this is what I got: 目前,这就是我得到的:
function lessons_learned_menu(){
...
$items['lessons-learned/projects/viewAll'] = array(
'title' => 'View All Projects - LL',
'description' => 'Review page that lists projects that are currently open.',
'page callback' => 'pmo_lessons_learned_projects_viewAll',
'access arguments' => array('Access pmo_lessons_learned'),
'type' => MENU_LOCAL_TASK
);
...
The access argument 'Access pmo_lessons_learned', everyone has (including Admins) and 'Administrator pmo_lessons_learned' only Admins have. 访问参数“ Access pmo_lessons_learned”,每个人(包括管理员)和只有管理员才具有的“ Administrator pmo_lessons_learned”。
Something that didn't work: 无效的东西:
if(!user_access("Administer pmo_lessons_learned")){
$items['lessons-learned/projects/viewAll'] = array(
'title' => 'View All Projects - LL',
'description' => 'Review page that lists projects that are currently open.',
'page callback' => 'pmo_lessons_learned_projects_viewAll',
'access arguments' => array('Access pmo_lessons_learned'),
'type' => MENU_LOCAL_TASK
);
}
else
{
$items['lessons-learned/projects/viewAll'] = array(
'title' => 'Review Projects',
...
}
When I tried to debug it, I always got the user as Admin (when it was non-Admin), therefore went to the else condition every time. 当我尝试调试它时,我总是以Admin(非管理员)身份获得用户,因此每次都进入else条件。
So I like to change the name of the tab if the user is not Admin and vice versa. 因此,如果用户不是Admin,则我想更改选项卡的名称,反之亦然。
The hook_menu
is invoked once to build and cache the menu items and is not supposed to run again until the cache is cleared. hook_menu
被调用一次以构建和缓存菜单项,除非清除缓存,否则不应再次运行它。 This hook is invoked by Drupal user 1 (admin), this explains why user_access("Administer pmo_lessons_learned")
returns true
. 这个钩子由Drupal用户1(admin)调用,这解释了为什么
user_access("Administer pmo_lessons_learned")
返回true
。
However you can use the 'title callback'
config in the menu items definition to generate the title with a function. 但是,您可以在菜单项定义中使用
'title callback'
配置来生成带有功能的标题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.