You are here

protected function EntitySubqueueAccessControlHandler::checkAccess in Entityqueue 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/EntitySubqueueAccessControlHandler.php, line 21

Class

EntitySubqueueAccessControlHandler
Defines the access control handler for the entity_subqueue entity type.

Namespace

Drupal\entityqueue

Code

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

  /** @var \Drupal\entityqueue\EntitySubqueueInterface $entity */
  switch ($operation) {
    case 'view':
      return AccessResult::allowedIfHasPermission($account, 'access content');
      break;
    case 'update':
      return AccessResult::allowedIfHasPermissions($account, [
        "update {$entity->bundle()} entityqueue",
        'manipulate all entityqueues',
        'administer entityqueue',
      ], 'OR');
      break;
    case 'delete':
      $can_delete_subqueue = AccessResult::allowedIf(!$entity
        ->getQueue()
        ->getHandlerPlugin()
        ->hasAutomatedSubqueues());
      $access_result = AccessResult::allowedIfHasPermissions($account, [
        "delete {$entity->bundle()} entityqueue",
        'manipulate all entityqueues',
        'administer entityqueue',
      ], 'OR')
        ->andIf($can_delete_subqueue)
        ->addCacheableDependency($entity
        ->getQueue());
      return $access_result;
      break;
    default:

      // No opinion.
      return AccessResult::neutral();
  }
}