You are here

function _menu_per_role_access in Menu Per Role 7

Same name and namespace in other branches
  1. 6 menu_per_role.module \_menu_per_role_access()

Determines access for a given menu item id.

Parameters

int $mlid: The menu item identifier.

Return value

bool|null NULL if this module does not forbid the viewing of this menu item, FALSE otherwise.

1 call to _menu_per_role_access()
menu_per_role_translated_menu_link_alter in ./menu_per_role.module
Implements hook_translated_menu_link_alter().

File

./menu_per_role.module, line 200
Allows restricting access to menu items per role.

Code

function _menu_per_role_access($mlid) {
  global $user;
  if (empty($mlid)) {
    return NULL;
  }

  // If menu is being edited allow user to see it in full.
  if (arg(0) == 'admin' && arg(1) == 'structure' && arg(2) == 'menu') {
    return NULL;
  }

  // Check whether this role has visibility access (must be present).
  $rids = _menu_per_role_get_roles($mlid, 0);
  if (!empty($rids) && count(array_intersect($rids, array_keys($user->roles))) == 0) {

    // Not permitted by the rids...
    return FALSE;
  }

  // Check whether this role has visibility access (must not be present).
  $hrids = _menu_per_role_get_roles($mlid, 1);
  if (!empty($hrids) && count(array_intersect($hrids, array_keys($user->roles))) > 0) {

    // Not permitted by the hrids...
    return FALSE;
  }

  // This module is not preventing user from seeing this menu entry.
  return NULL;
}