You are here

function workbench_access_entity_access in Workbench Access 8

Implements hook_entity_access().

File

./workbench_access.module, line 55
Contains workbench_access.module.

Code

function workbench_access_entity_access(EntityInterface $entity, $op, AccountInterface $account) {

  // Return net result of all enabled access schemes. If one scheme allows
  // access, then it is granted.
  // We don't care about the View operation right now.
  if ($op === 'view' || $op === 'view label' || $account
    ->hasPermission('bypass workbench access')) {

    // Return early.
    return AccessResult::neutral();
  }
  return array_reduce(\Drupal::entityTypeManager()
    ->getStorage('access_scheme')
    ->loadMultiple(), function (AccessResult $carry, AccessSchemeInterface $scheme) use ($entity, $op, $account) {
    $carry
      ->addCacheableDependency($scheme)
      ->cachePerPermissions()
      ->addCacheableDependency($entity);
    return $carry
      ->orIf($scheme
      ->getAccessScheme()
      ->checkEntityAccess($scheme, $entity, $op, $account));
  }, AccessResult::neutral());
}