You are here

function access_views_data_alter in Access Control Kit 7

Implements hook_views_data_alter().

File

./access.views.inc, line 163
Views integration for the access control kit module.

Code

function access_views_data_alter(&$data) {

  // Relate users to their access grants.
  $data['users']['access_user_grants'] = array(
    'title' => t('Access grants'),
    'help' => t('Relate a user to assigned roles for realms in an access scheme. This relationship will create one record for each access grant.'),
    'real field' => 'uid',
    'relationship' => array(
      'handler' => 'views_handler_relationship',
      'base' => 'access_grant',
      'base field' => 'uid',
      'label' => t('access grants'),
    ),
  );

  // Views integration for realm fields.
  foreach (access_scheme_load_multiple() as $scheme) {
    if ($scheme->realm_field['storage']['type'] != 'field_sql_storage') {
      continue;
    }
    $field_table = $scheme->realm_field['storage']['details']['sql'][FIELD_LOAD_CURRENT];
    $field_table_name = key($field_table);
    $field_table_value = $field_table[$field_table_name]['value'];

    // Allow the scheme to modify its realm field's views data.
    drupal_alter(array(
      'access_scheme_views_data',
      'access_scheme_' . $scheme->type . '_views_data',
    ), $data[$field_table_name], $field_table_value, $scheme->realm_field_name, $scheme->type);

    // Allow the object access handlers to modify the realm field's views data.
    foreach ($scheme->handlers as $object_type => $handler) {
      $handler
        ->viewsDataAlter($data, $scheme->machine_name, $field_table_name, $field_table_value, $object_type);
    }
  }
}