根据登录的用户更改 Drupal 模块中的选项卡名称。
Change tab names in Drupal module depending on the user Logged In.
在基于 Drupal 构建的 Intranet 上工作,在那里我得到了一个带有几个选项卡的模块。
有两种类型的用户,管理员和非管理员。我喜欢根据查看者更改选项卡的名称。
目前我得到的是:
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
);
...
访问参数'Access pmo_lessons_learned',每个人都有(包括管理员),'Administrator pmo_lessons_learned'只有管理员有。
一些无效的东西:
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',
...
}
当我尝试调试它时,我总是将用户设置为 Admin(当它不是 Admin 时),因此每次都进入 else 条件。
因此,如果用户不是管理员,我喜欢更改选项卡的名称,反之亦然。
hook_menu
被调用一次以构建和缓存菜单项,并且在清除缓存之前不应再次 运行。此挂钩由 Drupal 用户 1(管理员)调用,这解释了为什么 user_access("Administer pmo_lessons_learned")
returns true
。
但是您可以使用菜单项定义中的 'title callback'
配置来生成带有函数的标题。
在基于 Drupal 构建的 Intranet 上工作,在那里我得到了一个带有几个选项卡的模块。
有两种类型的用户,管理员和非管理员。我喜欢根据查看者更改选项卡的名称。
目前我得到的是:
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
);
...
访问参数'Access pmo_lessons_learned',每个人都有(包括管理员),'Administrator pmo_lessons_learned'只有管理员有。
一些无效的东西:
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',
...
}
当我尝试调试它时,我总是将用户设置为 Admin(当它不是 Admin 时),因此每次都进入 else 条件。
因此,如果用户不是管理员,我喜欢更改选项卡的名称,反之亦然。
hook_menu
被调用一次以构建和缓存菜单项,并且在清除缓存之前不应再次 运行。此挂钩由 Drupal 用户 1(管理员)调用,这解释了为什么 user_access("Administer pmo_lessons_learned")
returns true
。
但是您可以使用菜单项定义中的 'title callback'
配置来生成带有函数的标题。