function EntityAccessControlHandler::checkAccess

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php \Drupal\Core\Entity\EntityAccessControlHandler::checkAccess()
  2. 8.9.x core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php \Drupal\Core\Entity\EntityAccessControlHandler::checkAccess()
  3. 11.x core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php \Drupal\Core\Entity\EntityAccessControlHandler::checkAccess()

Performs access checks.

This method is supposed to be overwritten by extending classes that do their own custom access checking.

Parameters

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

string $operation: The entity operation. Usually one of 'view', 'view label', 'update' or 'delete'.

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

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

15 calls to EntityAccessControlHandler::checkAccess()
BaseFieldOverrideAccessControlHandler::checkAccess in core/lib/Drupal/Core/Field/BaseFieldOverrideAccessControlHandler.php
BlockAccessControlHandler::checkAccess in core/modules/block/src/BlockAccessControlHandler.php
BlockTypeAccessControlHandler::checkAccess in core/modules/block_content/src/BlockTypeAccessControlHandler.php
ContactFormAccessControlHandler::checkAccess in core/modules/contact/src/ContactFormAccessControlHandler.php
DateFormatAccessControlHandler::checkAccess in core/modules/system/src/DateFormatAccessControlHandler.php

... See full list

35 methods override EntityAccessControlHandler::checkAccess()
BaseFieldOverrideAccessControlHandler::checkAccess in core/lib/Drupal/Core/Field/BaseFieldOverrideAccessControlHandler.php
BlockAccessControlHandler::checkAccess in core/modules/block/src/BlockAccessControlHandler.php
BlockContentAccessControlHandler::checkAccess in core/modules/block_content/src/BlockContentAccessControlHandler.php
BlockTypeAccessControlHandler::checkAccess in core/modules/block_content/src/BlockTypeAccessControlHandler.php
CommentAccessControlHandler::checkAccess in core/modules/comment/src/CommentAccessControlHandler.php

... See full list

File

core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php, line 162

Class

EntityAccessControlHandler
Defines a default implementation for entity access control handler.

Namespace

Drupal\Core\Entity

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    if ($operation == 'delete' && $entity->isNew()) {
        return AccessResult::forbidden()->addCacheableDependency($entity);
    }
    if ($admin_permission = $this->entityType
        ->getAdminPermission()) {
        return AccessResult::allowedIfHasPermission($account, $admin_permission);
    }
    else {
        // No opinion.
        return AccessResult::neutral();
    }
}

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