You are here

function role_delegation_menu in Role Delegation 5

Same name and namespace in other branches
  1. 6 role_delegation.module \role_delegation_menu()
  2. 7 role_delegation.module \role_delegation_menu()

Implementation of hook_menu().

File

./role_delegation.module, line 39
This module allows site administrators to grant some roles the authority to assign selected roles to users, without them needing the 'administer access control' permission.

Code

function role_delegation_menu($may_cache) {
  global $user;
  $items = array();
  if (!$may_cache) {
    if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0) {
      $account = user_load(array(
        'uid' => arg(1),
      ));

      // Determine access to user profile page (same as user.module).
      $profile_access = $user->uid == arg(1) || user_access('access user profiles');
      $profile_access &= $account->status || user_access('administer users');

      // Determine access to role assignment page.
      $delegation_access = FALSE;
      if (!user_access('administer users') && !($delegation_access = user_access('administer access control'))) {
        $perms = role_delegation_perm();
        foreach ($perms as $perm) {
          if (user_access($perm)) {
            $delegation_access = TRUE;
            break;
          }
        }
      }
      $items[] = array(
        'path' => 'user/' . arg(1) . '/roles',
        'title' => t('Roles'),
        'callback' => 'drupal_get_form',
        'callback arguments' => array(
          'role_delegation_roles_form',
          $account,
        ),
        'access' => $profile_access && $delegation_access,
        'type' => MENU_LOCAL_TASK,
      );
    }
  }
  return $items;
}