0

I am theming an administrative page.
There are 2 roles (admin, role2) that have access to all the administrative pages. Now, I want to restrict the access to some URLs to the role2 role: Users with that role should be redirected to other pages. How is this done using the template?

I know I can use permissions to restrict the access, but I want to restrict the access basing on the URL being visited.

2

1 Answer 1

4

You can implement hook_menu_alter in your custom module and can provide function for 'access callback' property of the menu item.

<?php


/**
 * Implements hook_menu_item_alter()
 *
 */
function custom_feature_menu_alter(&$items) {

  $items['admin/structure/types']['access callback'] = 'custom_feature_access_callback';

}

/**
 * Custom access callback
 */

function custom_feature_access_callback($arg) {

  global $user;

  $roles = array_keys($user->roles);

  //Adding condition for the user roles. You can change 3 to your user role. I have tested this with administrator user role
  if (in_array(3, $roles)) {

    return FALSE;
  }
  else {
    return TRUE;
  }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.