views:

93

answers:

2

Hi friends,

I need to redirect a url for a user role.

URL From: http://www.example.com/admin

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

User Role: example-admin

So, when a user (example-admin role) login to admin panel with the url example.com/admin , he will not see Access Denied page, but redirected to content/filter as default login url.

Appreciate helps! Thanks a lot!

+2  A: 

You should consider using the Rules module ( http://drupal.org/project/rules ). Rules module allows you to issue redirects on login to an arbitrary URL. You can also check for conditions like the role of the User before issuing the redirect.

Sid NoParrots
+2  A: 

If you want to do it from code in a custom module, you could implement hook_menu_alter() and adjust the access callback function to use a custom override:

function yourModule_menu_alter(&$items) {
  // Override the access callback for the 'admin' page
  $items['admin']['access callback'] = 'yourModule_admin_access_override';
}

In that override, you perform the standard access check and return the result, but add the check for the specific role and redirect instead, if needed:

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;
}

(NOTE: Untested code, beware of typos)

You will have to trigger a rebuild of the menu registry for the menu alteration to be picked up.

Henrik Opel