You are here

class OrderUserViewAccessCheck in Commerce Core 8.2

Hierarchy

Expanded class hierarchy of OrderUserViewAccessCheck

File

modules/order/src/Access/OrderUserViewAccessCheck.php, line 11

Namespace

Drupal\commerce_order\Access
View source
class OrderUserViewAccessCheck implements AccessInterface {

  /**
   * Checks access to an order's user view mode.
   *
   * Draft orders are always denied as they have not yet been placed. Otherwise
   * access is delegated to entity access checks.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The route match.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   */
  public function checkAccess(RouteMatchInterface $route_match, AccountInterface $account) {
    $order = $route_match
      ->getParameter('commerce_order');
    if (!$order instanceof OrderInterface) {
      return AccessResult::neutral();
    }
    if ($order
      ->getState()
      ->getId() === 'draft') {
      return AccessResult::forbidden()
        ->addCacheableDependency($order);
    }
    return $order
      ->access('view', $account, TRUE);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OrderUserViewAccessCheck::checkAccess public function Checks access to an order's user view mode.