dongwen1935 2016-10-06 17:25
浏览 26
已采纳

根据用户登录,更改Drupal模块中的选项卡名称。

Working on Intranet built on Drupal where I got a module with couple of tabs.

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.

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.

So I like to change the name of the tab if the user is not Admin and vice versa.

  • 写回答

1条回答 默认 最新

  • download12749 2016-10-06 22:02
    关注

    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. This hook is invoked by Drupal user 1 (admin), this explains why user_access("Administer pmo_lessons_learned") returns true.

    However you can use the 'title callback' config in the menu items definition to generate the title with a function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵