function EntityAccess::entityAccess

Implements hook_entity_access().

File

core/modules/workspaces/src/Hook/EntityAccess.php, line 30

Class

EntityAccess
Defines a class for reacting to entity access control hooks.

Namespace

Drupal\workspaces\Hook

Code

public function entityAccess(EntityInterface $entity, $operation, AccountInterface $account) : AccessResultInterface {
    // 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.