我需要为用户角色重定向网址。
网址来自: http://www.example.com/admin
网址TO: http://www.example.com/admin/content/filter
用户角色: example-admin
因此,当用户(example-admin角色)使用url example.com/admin登录管理面板时,他将看不到“拒绝访问”页面,而是重定向到内容/过滤器作为默认登录URL。
欣赏帮助!非常感谢!
答案 0 :(得分:3)
您应该考虑使用规则模块(http://drupal.org/project/rules)。规则模块允许您在登录到任意URL时发出重定向。您还可以在发出重定向之前检查用户角色等条件。
答案 1 :(得分:2)
如果您想从自定义模块中的代码执行此操作,可以实现hook_menu_alter()
并调整访问回调函数以使用自定义覆盖:
function yourModule_menu_alter(&$items) {
// Override the access callback for the 'admin' page
$items['admin']['access callback'] = 'yourModule_admin_access_override';
}
在该覆盖中,您执行标准访问检查并返回结果,但是如果需要,请添加对特定角色的检查并重定向:
function yourModule_admin_access_override() {
global $user;
// Does the user have access anyway?
$has_access = user_access('access administration pages');
// Special case: If the user has no access, but is member of a specific role,
// redirect him instead of denying access:
if (!$has_access && in_array('example-admin', $user->roles)) {
drupal_goto('admin/content/filter'); // NOTE: Implicit exit() here.
}
return $has_access;
}
(注意:未经测试的代码,谨防拼写错误)
您必须触发重建菜单注册表才能获取菜单更改。