You are here

function access_object_schemes in Access Control Kit 7

Finds all access schemes that control access to a given object type.

Parameters

string $object_type: An access-controlled object type name (e.g., node, menu_link), as defined by hook_access_info().

bool $names_only: (optional) If set to TRUE, the returned array will contain only the names of the applicable access schemes, rather than fully loaded scheme entities. Defaults to FALSE.

Return value

array An array containing all access schemes that have an object access handler attached for the given object type, keyed by scheme machine name.

8 calls to access_object_schemes()
access_object_realms in ./access.module
Returns a list of an object's realm memberships.
access_user_object_access in ./access.module
Determines whether a user has a permission on an object via an access grant.
ack_menu_permission in ack_menu/ack_menu.module
Implements hook_permission().
ack_node_form_node_form_alter in ack_node/ack_node.module
Implements hook_form_BASE_FORM_ID_alter().
ack_node_permission in ack_node/ack_node.module
Implements hook_permission().

... See full list

File

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

Code

function access_object_schemes($object_type, $names_only = FALSE) {
  $object_schemes =& drupal_static(__FUNCTION__, array());

  // Get the machine names and IDs for all schemes that have a handler attached
  // for the given object type.
  if (!isset($object_schemes[$object_type])) {
    $object_schemes[$object_type] = db_query('SELECT s.machine_name, s.sid FROM {access_scheme} s INNER JOIN {access_handler} h ON s.machine_name = h.scheme WHERE h.object_type = :object_type', array(
      ':object_type' => $object_type,
    ))
      ->fetchAllKeyed();
  }

  // Return either the names or the objects for the applicable schemes.
  $scheme_list = array();
  if (!empty($object_schemes[$object_type])) {
    if ($names_only) {
      $scheme_list = array_intersect_key(access_scheme_names(), $object_schemes[$object_type]);
    }
    else {
      $schemes = access_scheme_load_multiple($object_schemes[$object_type]);
      foreach ($object_schemes[$object_type] as $machine_name => $sid) {
        $scheme_list[$machine_name] = $schemes[$sid];
      }
    }
  }
  return $scheme_list;
}