You are here

PriceListItemTypeAccessControlHandler.php in Commerce Pricelist 8

File

src/PriceListItemTypeAccessControlHandler.php
View source
<?php

namespace Drupal\commerce_pricelist;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;

/**
 * Defines the access control handler for the price list item type entity type.
 *
 * @see \Drupal\commerce_pricelist\Entity\PriceListItemType
 */
class PriceListItemTypeAccessControlHandler extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    switch ($operation) {
      case 'view':
        return AccessResult::allowedIfHasPermission($account, 'view price_list');
      case 'delete':
        if ($entity
          ->isLocked()) {
          return AccessResult::forbidden()
            ->addCacheableDependency($entity);
        }
        else {
          return parent::checkAccess($entity, $operation, $account)
            ->addCacheableDependency($entity);
        }
        break;
      default:
        return parent::checkAccess($entity, $operation, $account);
    }
  }

}

Classes

Namesort descending Description
PriceListItemTypeAccessControlHandler Defines the access control handler for the price list item type entity type.