我需要为用户角色重定向一个 url。
网址来自: http ://www.example.com/admin
网址: http ://www.example.com/admin/content/filter
用户角色: example-admin
因此,当用户(example-admin 角色)使用 url example.com/admin 登录管理面板时,他不会看到 Access Denied 页面,而是重定向到 content/filter 作为默认登录 url。
感谢帮助!非常感谢!
我需要为用户角色重定向一个 url。
网址来自: http ://www.example.com/admin
网址: http ://www.example.com/admin/content/filter
用户角色: example-admin
因此,当用户(example-admin 角色)使用 url example.com/admin 登录管理面板时,他不会看到 Access Denied 页面,而是重定向到 content/filter 作为默认登录 url。
感谢帮助!非常感谢!
您应该考虑使用规则模块(http://drupal.org/project/rules)。规则模块允许您在登录时发出重定向到任意 URL。您还可以在发出重定向之前检查用户角色等条件。
如果您想从自定义模块中的代码执行此操作,您可以实现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;
}
(注意:未经测试的代码,谨防拼写错误)
您将不得不触发菜单注册表的重建,以便获取菜单更改。