function hook_ENTITY_TYPE_access

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_access()
  2. 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_access()
  3. 10 core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_access()

Control entity operation access for a specific entity type.

Note that this hook is not called for listings (e.g., from entity queries and Views). For nodes, see Node access rights for a full explanation. For other entity types, see hook_query_TAG_alter().

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to check access to.

string $operation: The operation that is to be performed on $entity. Usually one of:

  • "view"
  • "update"
  • "delete".

\Drupal\Core\Session\AccountInterface $account: The account trying to access the entity.

Return value

\Drupal\Core\Access\AccessResultInterface The access result. hook_entity_access() has detailed documentation.

See also

\Drupal\Core\Entity\EntityAccessControlHandler

hook_ENTITY_TYPE_create_access()

hook_entity_access()

hook_query_TAG_alter()

Related topics

10 functions implement hook_ENTITY_TYPE_access()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

field_test_boolean_access_denied_entity_field_access in core/modules/field/tests/modules/field_test_boolean_access_denied/field_test_boolean_access_denied.module
Implements hook_entity_field_access().
image_access_test_hidden_entity_field_access in core/modules/image/tests/modules/image_access_test_hidden/image_access_test_hidden.module
Implements hook_entity_field_access().
jsonapi_test_field_access_entity_field_access in core/modules/jsonapi/tests/modules/jsonapi_test_field_access/jsonapi_test_field_access.module
Implements hook_entity_field_access().
jsonapi_test_field_filter_access_jsonapi_entity_field_filter_access in core/modules/jsonapi/tests/modules/jsonapi_test_field_filter_access/jsonapi_test_field_filter_access.module
Implements hook_jsonapi_entity_field_field_access().
language_entity_field_access_test_entity_field_access in core/modules/language/tests/language_entity_field_access_test/language_entity_field_access_test.module
Implements hook_entity_field_access().

... See full list

File

core/lib/Drupal/Core/Entity/entity.api.php, line 744

Code

function hook_ENTITY_TYPE_access(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Session\AccountInterface $account) : \Drupal\Core\Access\AccessResultInterface {
    // No opinion.
    return AccessResult::neutral();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.