function _devel_node_access_ng_alter
Mimics hook_node_grants_alter() and traces what each module does with it.
Parameters
object $grants: An indexed array of grant records, augmented by the '#module' key, as created by _devel_node_access_module_invoke_all('node_grants'). This array is updated by the hook_node_grants_alter() implementations.
$node: The node that the grant records belong to.
Return value
A tree representation of the grant records in $grants including their history: $data[$realm][$gid]
- ['cur']: TRUE or FALSE whether the gid is present or not
- ['ori'][]: An array of module names that contributed this grant (if any)
- ['chg'][]: An array of changes, such as
- 'added' if module name is a prefix if the $realm,
- 'added by module' otherwise, or
- 'removed by module'
1 call to _devel_node_access_ng_alter()
- devel_node_access_block_view in ./
devel_node_access.module - Implements hook_block_view().
File
-
./
devel_node_access.module, line 478
Code
function _devel_node_access_ng_alter(&$grants, $account, $op) {
//dpm($grants, '_devel_node_access_ng_alter(): grants IN');
$dummy = array();
drupal_alter('node_grants', $dummy, $account, $op);
static $drupal_static = array();
isset($drupal_static['drupal_alter']) || ($drupal_static['drupal_alter'] =& drupal_static('drupal_alter'));
$functions = $drupal_static['drupal_alter'];
// Build the initial structure.
$data = array();
foreach ($grants as $realm => $gids) {
foreach ($gids as $i => $gid) {
if ($i !== '#module') {
$data[$realm][$gid]['cur'] = TRUE;
$data[$realm][$gid]['ori'][] = $gids['#module'];
}
}
unset($grants[$realm]['#module']);
}
// Simulate drupal_alter('node_grants', $grants, $account, $op);
foreach ($functions['node_grants'] as $function) {
// Call hook_node_grants_alter() for one module at a time and analyze.
$function($grants, $account, $op);
// <==
$module = substr($function, 0, strlen($function) - 18);
// Check for new gids.
foreach ($grants as $realm => $gids) {
foreach ($gids as $i => $gid) {
if (empty($data[$realm][$gid]['cur'])) {
$data[$realm][$gid]['cur'] = TRUE;
$data[$realm][$gid]['chg'][] = 'added by ' . $module;
}
}
}
// Check for removed gids.
foreach ($data as $realm => $gids) {
foreach ($gids as $gid => $history) {
if ($history['cur'] && array_search($gid, $grants[$realm]) === FALSE) {
$data[$realm][$gid]['cur'] = FALSE;
$data[$realm][$gid]['chg'][] = 'removed by ' . $module;
}
}
}
}
//dpm($data, '_devel_node_access_ng_alter() returns');
//dpm($grants, '_devel_node_access_ng_alter(): grants OUT');
return $data;
}