function hook_entity_access
Same name and namespace in other branches
- 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_access()
- 10 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_access()
- 11.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_access()
Control entity operation access.
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. The final result is calculated by using \Drupal\Core\Access\AccessResultInterface::orIf() on the result of every hook_entity_access() and hook_ENTITY_TYPE_access() implementation, and the result of the entity-specific checkAccess() method in the entity access control handler. Be careful when writing generalized access checks shared between routing and entity checks: routing uses the andIf() operator. So returning an isNeutral() does not determine entity access at all but it always ends up denying access while routing.
See also
\Drupal\Core\Entity\EntityAccessControlHandler
Related topics
13 functions implement hook_entity_access()
Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.
- ContentModerationHooks::entityAccess in core/
modules/ content_moderation/ src/ Hook/ ContentModerationHooks.php - Implements hook_entity_access().
- ContentTranslationTestHooks::entityAccess in core/
modules/ content_translation/ tests/ modules/ content_translation_test/ src/ Hook/ ContentTranslationTestHooks.php - Implements hook_entity_access().
- content_moderation_entity_access in core/
modules/ content_moderation/ content_moderation.module - Implements hook_entity_access().
- content_translation_test_entity_access in core/
modules/ content_translation/ tests/ modules/ content_translation_test/ content_translation_test.module - Implements hook_entity_access().
- EntityAccess::entityAccess in core/
modules/ workspaces/ src/ Hook/ EntityAccess.php - Implements hook_entity_access().
1 invocation of hook_entity_access()
- EntityAccessControlHandler::access in core/
lib/ Drupal/ Core/ Entity/ EntityAccessControlHandler.php - Checks access to an operation on a given entity or entity translation.
File
-
core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 716
Code
function hook_entity_access(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Session\AccountInterface $account) {
// No opinion.
return AccessResult::neutral();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.