You are here

function block_access_entity_access in Block Access 8

Implements hook_entity_access().

File

./block_access.module, line 16
Main module functionality.

Code

function block_access_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
  if ($entity
    ->getEntityTypeId() !== 'block_content') {
    return AccessResult::neutral();
  }

  /** @var \Drupal\block_content\BlockContentInterface $entity */
  $any = sprintf('%s any %s block_content', $operation, $entity
    ->bundle());
  $own = sprintf('%s own %s block_content', $operation, $entity
    ->bundle());
  return AccessResult::allowedIfHasPermission($account, $any)
    ->orIf(AccessResult::allowedIfHasPermission($account, $own)
    ->andIf(AccessResult::allowedIf($entity instanceof RevisionLogInterface && $entity
    ->getRevisionUser() && $entity
    ->getRevisionUser()
    ->id() === $account
    ->id()))
    ->addCacheableDependency($entity));
}