function EntityAccess::entityOperationAccess

Same name and namespace in other branches
  1. 9 core/modules/workspaces/src/EntityAccess.php \Drupal\workspaces\EntityAccess::entityOperationAccess()
  2. 8.9.x core/modules/workspaces/src/EntityAccess.php \Drupal\workspaces\EntityAccess::entityOperationAccess()
  3. 11.x core/modules/workspaces/src/EntityAccess.php \Drupal\workspaces\EntityAccess::entityOperationAccess()

Implements a hook bridge for hook_entity_access().

Parameters

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

string $operation: The operation being performed.

\Drupal\Core\Session\AccountInterface $account: The user account making the to check access for.

Return value

\Drupal\Core\Access\AccessResult The result of the access check.

See also

hook_entity_access()

File

core/modules/workspaces/src/EntityAccess.php, line 85

Class

EntityAccess
Service wrapper for hooks relating to entity access control.

Namespace

Drupal\workspaces

Code

public function entityOperationAccess(EntityInterface $entity, $operation, AccountInterface $account) {
  // Workspaces themselves are handled by their own access handler and we
  // should not try to do any access checks for entity types that can not
  // belong to a workspace.
  if (!$this->workspaceInfo
    ->isEntitySupported($entity) || !$this->workspaceManager
    ->hasActiveWorkspace()) {
    return AccessResult::neutral();
  }
  // Prevent the deletion of entities with a published default revision.
  if ($operation === 'delete') {
    $active_workspace = $this->workspaceManager
      ->getActiveWorkspace();
    $is_deletable = $this->workspaceInfo
      ->isEntityDeletable($entity, $active_workspace);
    return AccessResult::forbiddenIf(!$is_deletable)->addCacheableDependency($entity)
      ->addCacheableDependency($active_workspace);
  }
  return $this->bypassAccessResult($account);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.