By xano on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
Any entity access control handler that extends \Drupal\Core\Entity\EntityAccessControlHandler will now invoke hook_entity_access() and hook_entity_create_access() next to hook_ENTITY_TYPE_access() and hook_ENTITY_TYPE_create_access(). To check the entity type in hook_entity_access(), call $entity->entityType(). See entity.api.php the hooks' arguments and return values.
Example:
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Implements hook_entity_access().
*/
function hook_entity_access(EntityInterface $entity, $operation, AccountInterface $account, $langcode) {
$entity_types = array('foo', 'bar');
if (in_array($entity->entityType(), $entity_types)) {
return TRUE;
}
return NULL;
}
/**
* Implements hook_entity_create_access().
*/
function hook_entity_create_access(AccountInterface $account, $langcode, $entity_bundle) {
if ($account->hasPermission('foo')) {
return TRUE;
}
return NULL;
}
Impacts:
Module developers