Are calls to the access()
method on entity objects which is provided by ContentEntityBase affected by hook_ENTITY_TYPE_access()
?
I am asking because the Paragraphs module, in src/ParagraphAccessControllHandler.php, contains the following code.
protected function checkAccess(EntityInterface $paragraph, $operation, AccountInterface $account) {
// Allowed when the operation is not view or the status is true.
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
if ($paragraph->getParentEntity() != NULL) {
// Delete permission on the paragraph, should just depend on 'update'
// access permissions on the parent.
$operation = ($operation == 'delete') ? 'update' : $operation;
$parent_access = $paragraph->getParentEntity()->access($operation, $account, TRUE);
return AccessResult::allowedIf($operation != 'view' || $paragraph->status->value)
->andIf($parent_access);
}
return AccessResult::allowedIf($operation != 'view' || $paragraph->status->value);
}
The following hook is in the Block content permissions module, in block_content_permissions.module.
function block_content_permissions_block_content_access(EntityInterface $entity, $operation, AccountInterface $account) {
// Disallow operation access to entity based on user's permissions.
switch ($operation) {
case 'delete':
case 'update':
// Get block content type.
$bundle_type = $entity->bundle();
// Check permissions for block content.
// Negate to hide operation link.
return AccessResult::forbiddenIf(!(
$account->hasPermission('administer block content') &&
$account->hasPermission("$operation any $bundle_type block content")
));
}
}
By using kint()
, I can tell that checkAccess()
is being called, but the hook isn't running. I realize that the block content module is experimental, but theoretically this should work and is in fact working for performing actions on blocks themselves.