W3cubDocs

/Drupal 8

protected function EntityAccessControlHandler::checkAccess

protected EntityAccessControlHandler::checkAccess(EntityInterface $entity, $operation, AccountInterface $account)

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.

File

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

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, $this->entityType->getAdminPermission());
  }
  else {
    // No opinion.
    return AccessResult::neutral();
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityAccessControlHandler.php/function/EntityAccessControlHandler::checkAccess/8.1.x