You are here

protected function ScheduledUpdateAccessControlHandler::checkAccess in Scheduled Updates 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/ScheduledUpdateAccessControlHandler.php, line 25
Contains \Drupal\scheduled_updates\ScheduledUpdateAccessControlHandler.

Class

ScheduledUpdateAccessControlHandler
Access controller for the Scheduled update entity.

Namespace

Drupal\scheduled_updates

Code

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

  /** @var ScheduledUpdate $entity */
  if ($account
    ->hasPermission('administer scheduled updates')) {
    return AccessResult::allowed();
  }
  if ($operation == 'view') {
    return AccessResult::allowedIfHasPermission($account, 'view scheduled update entities');
  }
  $type_id = $entity
    ->bundle();
  if ($entity
    ->getOwnerId() == $account
    ->id()) {

    // If owner that needs either own or any permission, not both.
    return AccessResult::allowedIfHasPermissions($account, [
      "{$operation} any {$type_id} scheduled updates",
      "{$operation} own {$type_id} scheduled updates",
    ], 'OR');
  }
  else {
    return AccessResult::allowedIfHasPermission($account, "{$operation} any {$type_id} scheduled updates");
  }
}