diff --git a/uc_order/src/Entity/OrderStatus.php b/uc_order/src/Entity/OrderStatus.php index 110983f..d36a697 100644 --- a/uc_order/src/Entity/OrderStatus.php +++ b/uc_order/src/Entity/OrderStatus.php @@ -5,6 +5,8 @@ namespace Drupal\uc_order\Entity; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\uc_order\OrderStatusInterface; +use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Access\AccessResult; /** * Defines the order status entity. @@ -162,4 +164,21 @@ class OrderStatus extends ConfigEntityBase implements OrderStatusInterface { return $options; } + /** + * + */ + public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) { + + if ( + $operation == 'view' && + (\Drupal::currentUser()->hasPermission('view all orders') || \Drupal::currentUser()->hasPermission('view own orders')) + ) { + $result = AccessResult::allowed()->cachePerPermissions(); + return $return_as_object ? $result : $result->isAllowed(); + } else { + $result = AccessResult::forbidden()->cachePerPermissions(); + return $return_as_object ? $result : $result->isAllowed(); + } + } + }