You are here

function entity_access in Entity API 7

Determines whether the given user can perform actions on an entity.

For create operations, the pattern is to create an entity and then check if the user has create access.

$node = entity_create('node', array(
  'type' => 'page',
));
$access = entity_access('create', 'node', $node, $account);

Parameters

$op: The operation being performed. One of 'view', 'update', 'create' or 'delete'.

$entity_type: The entity type of the entity to check for.

$entity: Optionally an entity to check access for. If no entity is given, it will be determined whether access is allowed for all entities of the given type.

$account: The user to check for. Leave it to NULL to check for the global user.

Return value

bool Whether access is allowed or not. If the entity type does not specify any access information, NULL is returned.

See also

entity_type_supports()

15 calls to entity_access()
EntityAPICommentNodeAccessTestCase::testCommentNodeAccess in ./entity.test
Tests comment access when node access is enabled.
EntityDrupalWrapper::entityAccess in includes/entity.wrapper.inc
Checks whether the operation $op is allowed on the entity.
EntityMetadataIntegrationTestCase::testComments in ./entity.test
Test properties of a comment.
EntityMetadataIntegrationTestCase::testCRUDfunctions in ./entity.test
Runs some generic tests on each entity.
EntityMetadataNodeAccessTestCase::assertNodeMetadataAccess in ./entity.test
Asserts node_access() correctly grants or denies access.

... See full list

3 string references to 'entity_access'
EntityBundleableUIController::hook_menu in includes/entity.ui.inc
Provides definitions for implementing hook_menu().
EntityContentUIController::hook_menu in includes/entity.ui.inc
Provides definitions for implementing hook_menu().
EntityDefaultUIController::hook_menu in includes/entity.ui.inc
Provides definitions for implementing hook_menu().

File

./entity.module, line 669

Code

function entity_access($op, $entity_type, $entity = NULL, $account = NULL) {
  if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) {
    return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type);
  }
}