You are here

function module_grants_by_module in Module Grants 7

Return a map, keyed by module name, of grant arrays (keys are realms, values are array of grants) associated with the module, as returned by that module's hook_node_grants().

This is similar to node.module's node_access_grants(), but returns the grants by module instead of all at once.

Parameters

$op: The operation, i.e 'view', 'update' or 'delete'

$account: User account object

$nid: Optional. If passed in, only modules with at least one row in the node_acces table for the supplied nid are included (lenient interpretation of absence of node grants). If not passed in, then all modules implementing hook_node_grants() will be included (strict).

Return value

An array of module grants, keyed by module name. If a module implements hook_node_grants but didn't return any grants for this op/account/node, we still return it as a key with empty array as value.

3 calls to module_grants_by_module()
module_grants_apply_subquery_for_node_query_node_access_alter in ./module_grants.module
The core function of this module, applies node access grants condition to the node access query alter
module_grants_get_node_access_result in ./module_grants.module
The core function of this module, calculate result for node_access()
module_grants_get_node_access_view_all_nodes_result in ./module_grants.module
The core function of this module, calculate result for node_access_view_all_nodes()

File

./module_grants.module, line 421

Code

function module_grants_by_module($op, $account = NULL) {
  if (!isset($account)) {
    $account = $GLOBALS['user'];
  }

  // Fetch node access grants from other modules.
  $grants = module_invoke_all('node_grants', $account, $op);

  // Allow modules to alter the assigned grants.
  drupal_alter('node_grants', $grants, $account, $op);

  // Now we need to assign each realm in the grants to its module
  $all_grants = array();
  foreach (module_implements('node_grants') as $module) {
    $module_grants = array();
    foreach ($grants as $realm => $gids) {
      if (module_grants_is_realm_by_module($realm, $module)) {
        $module_grants[$realm] = $gids;
        unset($grants[$realm]);
      }
    }
    $all_grants[$module] = $module_grants;
  }
  return $all_grants;
}