function NodeAccessControlHandler::access

Same name in other branches
  1. 9 core/modules/node/src/NodeAccessControlHandler.php \Drupal\node\NodeAccessControlHandler::access()
  2. 8.9.x core/modules/node/src/NodeAccessControlHandler.php \Drupal\node\NodeAccessControlHandler::access()
  3. 10 core/modules/node/src/NodeAccessControlHandler.php \Drupal\node\NodeAccessControlHandler::access()

Overrides EntityAccessControlHandler::access

1 call to NodeAccessControlHandler::access()
NodeAccessControlHandler::checkAccess in core/modules/node/src/NodeAccessControlHandler.php
Performs access checks.

File

core/modules/node/src/NodeAccessControlHandler.php, line 89

Class

NodeAccessControlHandler
Defines the access control handler for the node entity type.

Namespace

Drupal\node

Code

public function access(EntityInterface $entity, $operation, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
    $account = $this->prepareUser($account);
    // Only bypass if not a revision operation, to retain compatibility.
    if ($account->hasPermission('bypass node access') && !isset(static::REVISION_OPERATION_MAP[$operation])) {
        $result = AccessResult::allowed()->cachePerPermissions();
        return $return_as_object ? $result : $result->isAllowed();
    }
    if (!$account->hasPermission('access content')) {
        $result = AccessResult::forbidden("The 'access content' permission is required.")->cachePerPermissions();
        return $return_as_object ? $result : $result->isAllowed();
    }
    $result = parent::access($entity, $operation, $account, TRUE)->cachePerPermissions();
    return $return_as_object ? $result : $result->isAllowed();
}

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