You are here

protected function PollAccessControlHandler::checkAccess in Poll 8

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.

Overrides EntityAccessControlHandler::checkAccess

File

src/PollAccessControlHandler.php, line 29

Class

PollAccessControlHandler
Defines an access control handler for the poll entity.

Namespace

Drupal\poll

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {

  // Allow view access if the user has the access polls permission.
  if ($operation == 'view') {
    return AccessResult::allowedIfHasPermission($account, 'access polls');
  }
  elseif ($operation == 'update' && !$account
    ->isAnonymous() && $account
    ->id() == $entity
    ->get('uid')->target_id) {
    return AccessResult::allowedIfHasPermissions($account, [
      'edit own polls',
      'administer polls',
    ], 'OR');
  }

  // Otherwise fall back to the parent which checks the administer polls
  // permission.
  return parent::checkAccess($entity, $operation, $account);
}