function _devel_node_access_nar_alter

Mimics hook_node_access_records_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_access_records'). This array is updated by the hook_node_access_records_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] ['original'] - grant record before processing ['current'] - grant record after processing (if still present) ['changes'][]['op'] - change message (add/change/delete by $module) ['grant'] - grant record after change (unless deleted)

1 call to _devel_node_access_nar_alter()
devel_node_access_block_view in ./devel_node_access.module
Implements hook_block_view().

File

./devel_node_access.module, line 384

Code

function _devel_node_access_nar_alter(&$grants, $node) {
    
    //dpm($grants, '_devel_node_access_nar_alter(): grants IN');
    $dummy = array();
    drupal_alter('node_access_records', $dummy, $node);
    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 tree (and check for duplicates).
    $data = _devel_node_access_build_nar_data($grants, $node, 'hook_node_access_records()');
    // Simulate drupal_alter('node_access_records', $grants, $node);
    foreach ($functions['node_access_records'] as $function) {
        // Call hook_node_access_records_alter() for one module at a time and
        // analyze.
        $function($grants, $node);
        // <==
        $module = substr($function, 0, strlen($function) - 26);
        foreach ($grants as $i => $grant) {
            if (empty($data[$grant['realm']][$grant['gid']]['current'])) {
                // It's an added grant.
                $data[$grant['realm']][$grant['gid']]['current'] = $grant;
                $data[$grant['realm']][$grant['gid']]['current']['#module'] = $module;
                $data[$grant['realm']][$grant['gid']]['changes'][] = array(
                    'op' => 'added by ' . $module,
                    'grant' => $grant,
                );
                $grants[$i]['#module'] = $module;
            }
            else {
                // It's an existing grant, check for changes.
                $view = $update = $delete = FALSE;
                foreach (array(
                    'view',
                    'update',
                    'delete',
                ) as $op) {
                    ${$op} = $grant["grant_{$op}"] - $data[$grant['realm']][$grant['gid']]['current']["grant_{$op}"];
                }
                $priority = $grant['priority'] - $data[$grant['realm']][$grant['gid']]['current']['priority'];
                if ($view || $update || $delete || $priority) {
                    // It was changed.
                    $data[$grant['realm']][$grant['gid']]['current'] = $grant;
                    $data[$grant['realm']][$grant['gid']]['current']['#module'] = $module;
                    $data[$grant['realm']][$grant['gid']]['changes'][] = array(
                        'op' => 'altered by ' . $module,
                        'grant' => $grant,
                    );
                    $grants[$i]['#module'] = $module;
                }
            }
            $data[$grant['realm']][$grant['gid']]['found'] = TRUE;
        }
        // Check for newly introduced duplicates.
        _devel_node_access_build_nar_data($grants, $node, 'hook_node_access_records_alter()');
        // Look for grant records that have disappeared.
        foreach ($data as $realm => $data2) {
            foreach ($data2 as $gid => $data3) {
                if (empty($data[$realm][$gid]['found']) && isset($data[$realm][$gid]['current'])) {
                    unset($data[$realm][$gid]['current']);
                    $data[$realm][$gid]['changes'][] = array(
                        'op' => 'removed by ' . $module,
                    );
                }
                else {
                    unset($data[$realm][$gid]['found']);
                }
            }
        }
    }
    
    //dpm($data, '_devel_node_access_nar_alter() returns');
    
    //dpm($grants, '_devel_node_access_nar_alter(): grants OUT');
    return $data;
}