You are here

function _devel_node_access_build_nar_data in Devel 7

Builds an associative array of grant records and their history.

If there are duplicate records, display an error message.

Parameters

$grants: An indexed array of grant records, augmented by the '#module' key, as created by _devel_node_access_module_invoke_all('node_access_records').

$node: The node that the grant records belong to.

$function: The name of the hook that produced the grants array, in case we need to display an error message.

Return value

See _devel_node_access_nar_alter() for the description of the result.

1 call to _devel_node_access_build_nar_data()
_devel_node_access_nar_alter in ./devel_node_access.module
Mimics hook_node_access_records_alter() and traces what each module does with it.

File

./devel_node_access.module, line 330
Functions for debugging node access permissions.

Code

function _devel_node_access_build_nar_data($grants, $node, $function) {
  $data = array();
  $duplicates = array();
  foreach ($grants as $grant) {
    if (empty($data[$grant['realm']][$grant['gid']])) {
      $data[$grant['realm']][$grant['gid']] = array(
        'original' => $grant,
        'current' => $grant,
        'changes' => array(),
      );
    }
    else {
      if (empty($duplicates[$grant['realm']][$grant['gid']])) {
        $duplicates[$grant['realm']][$grant['gid']][] = $data[$grant['realm']][$grant['gid']]['original'];
      }
      $duplicates[$grant['realm']][$grant['gid']][] = $grant;
    }
  }
  if (!empty($duplicates)) {

    // generate an error message
    $msg = t('Devel Node Access has detected duplicate records returned from %function:', array(
      '%function' => $function,
    ));
    $msg .= '<ul>';
    foreach ($duplicates as $realm => $data_by_realm) {
      foreach ($data_by_realm as $gid => $data_by_realm_gid) {
        $msg .= '<li><ul>';
        foreach ($data_by_realm_gid as $grant) {
          $msg .= "<li>{$node->nid}/{$realm}/{$gid}/" . ($grant['grant_view'] ? 1 : 0) . ($grant['grant_update'] ? 1 : 0) . ($grant['grant_delete'] ? 1 : 0) . ' by ' . $grant['#module'] . '</li>';
        }
        $msg .= '</ul></li>';
      }
    }
    $msg .= '</ul>';
    drupal_set_message($msg, 'error', FALSE);
  }
  return $data;
}