/Drupal 8

function hook_entity_access

hook_entity_access(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Session\AccountInterface $account)

Control entity operation access.


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

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

\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




Related topics

Entity API
Describes how to define and manipulate content and configuration entities.
Define functions that alter the behavior of Drupal core.


core/lib/Drupal/Core/Entity/entity.api.php, line 558
Hooks and documentation related to entities.


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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.