You are here

protected function OrderStatusAccessControlHandler::checkAccess in Ubercart 8.4

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

uc_order/src/OrderStatusAccessControlHandler.php, line 18

Class

OrderStatusAccessControlHandler
Defines the access control handler for Ubercart order statuses.

Namespace

Drupal\uc_order

Code

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

  /** @var \Drupal\uc_order\OrderStatusInterface $order_status */
  switch ($operation) {
    case 'view':

      // User can view order statuses, who has permission to view orders or
      // has permission to administer the order workflow.
      if ($account
        ->hasPermission('view all orders') || $account
        ->hasPermission('view own orders') || $account
        ->hasPermission('administer order workflow')) {
        return AccessResult::allowed()
          ->cachePerPermissions();
      }
      else {
        return AccessResult::forbidden()
          ->cachePerPermissions();
      }
    case 'update':

      // User can update an order status, if has permission to administer
      // order workflow.
      return AccessResult::allowedIfHasPermission($account, 'administer order workflow')
        ->cachePerPermissions()
        ->cachePerUser();
    case 'delete':

      // User can delete an order status, if has permission to administer
      // order workflow.
      return AccessResult::allowedIfHasPermission($account, 'administer order workflow')
        ->cachePerPermissions()
        ->cachePerUser();
  }
  return AccessResult::neutral();
}