我需要重定向用户角色的URL。

URL来自: http://www.example.com/admin

URL到: http://www.example.com/admin/content/filter

用户角色: 例子

因此,当用户(示例ADMIN角色)登录到使用URL example.com/admin进行管理面板时,他不会看到访问拒绝的页面,而是将内容/过滤器重定向为默认登录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;
}

(注意:未经测试的代码,当心错别字)

您将不得不触发菜单注册表的重建,以便挑选菜单更改。

其他提示

您应该考虑使用规则模块( http://drupal.org/project/rules )。规则模块允许您在登录时发布重定向到任意URL。您还可以在发出重定向之前检查用户的角色等条件。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top