You are here

function access_info in Access Control Kit 7

Returns information on available access-controlled object types.

Parameters

string $type: (optional) An object type, such as 'node' or 'menu_link'.

Return value

array|false The information array for the requested $type, or FALSE if not found. If $type is omitted, returns information for all available object types in an array indexed by object type. Type information is returned as an associative array with the following keys:

  • label: The human-readable name of this object type (e.g., "Content", "Menu link").
  • type: The machine name of this object type (e.g., node, menu_link).
  • module: The module that provides ACK-compatibility for the object type.
  • fieldable: Boolean indicating whether or not this object type is a fieldable entity, as defined by hook_entity_info().
  • handlers: An array listing the access handlers that support this object type, as defined in hook_access_handler_info().

See also

hook_access_info()

hook_access_info_alter()

2 calls to access_info()
access_scheme_features_export_render in ./access.features.inc
Implements hook_features_export_render().
access_scheme_form in ./access_schemes.admin.inc
Form constructor for the access scheme add/edit form.
2 string references to 'access_info'
access_hook_info in ./access.module
Implements hook_hook_info().
access_info_cache_clear in ./access.module
Clears cached ACK API information.

File

./access.module, line 688
The access control kit module.

Code

function access_info($type = NULL) {
  $info =& drupal_static(__FUNCTION__, array());
  if (empty($info)) {
    $cache = cache_get('access_info');
    if ($cache) {
      $info = $cache->data;
    }
    else {
      foreach (module_implements('access_info') as $module) {
        $module_info = module_invoke($module, 'access_info');
        if ($module_info) {
          foreach ($module_info as $object_type => $object_info) {

            // Merge in default values.
            $object_info += array(
              'label' => '',
            );

            // Set inferred values.
            $object_info['type'] = $object_type;
            $object_info['module'] = $module;
            $object_info['handlers'] = array();

            // Check whether the object is a fieldable entity.
            $entity_info = entity_get_info($object_type);
            $object_info['fieldable'] = empty($entity_info) ? FALSE : $entity_info['fieldable'];
            $info[$object_type] = $object_info;
          }
        }
      }
      drupal_alter('access_info', $info);
      cache_set('access_info', $info);
    }

    // Find handlers that support this object type. This information is already
    // cached in access_handler_info(), so we only include this in the static
    // variable, not in the cache_set() above.
    $handlers = access_handler_info();
    foreach ($info as $object_type => $object_info) {
      foreach ($handlers as $handler_name => $handler_info) {

        // If the object is a fieldable entity and the handler supports
        // fieldable entities, or if the handler explicitly supports this
        // object type, add the handler to the list.
        if ($object_info['fieldable'] && in_array('fieldable entity', $handler_info['object types']) || in_array($object_type, $handler_info['object types'])) {
          $info[$object_type]['handlers'][] = $handler_name;
        }
      }
    }
  }
  if (isset($type)) {
    return isset($info[$type]) ? $info[$type] : FALSE;
  }
  return $info;
}