You are here

protected function ProductVariationTypeAccessControlHandler::checkAccess in Commerce Core 8.2

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 CommerceBundleAccessControlHandler::checkAccess

File

modules/product/src/ProductVariationTypeAccessControlHandler.php, line 28

Class

ProductVariationTypeAccessControlHandler
Controls access to product variation type entities.

Namespace

Drupal\commerce_product

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
  if ($operation === 'view label') {
    $bundle = $entity
      ->id();
    $permissions = [
      'administer commerce_product',
      'access commerce_product overview',
      "manage {$bundle} commerce_product_variation",
    ];
    return AccessResult::allowedIfHasPermissions($account, $permissions, 'OR');
  }
  else {
    return parent::checkAccess($entity, $operation, $account);
  }
}