You are here

protected function CountryListAccessControlHandler::checkAccess in Country, State and City Fields 8

Link the activities to the permissions. checkAccess() is called with the $operation as defined in the routing.yml file.

Overrides EntityAccessControlHandler::checkAccess

File

src/CountryListAccessControlHandler.php, line 21

Class

CountryListAccessControlHandler
Access controller for the countrylist entity.

Namespace

Drupal\country_state_city

Code

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

  // Check the admin_permission as defined in your @ContentEntityType
  // annotation.
  $admin_permission = $this->entityType
    ->getAdminPermission();
  if ($account
    ->hasPermission($admin_permission)) {
    return AccessResult::allowed();
  }
  switch ($operation) {
    case 'view':
      return AccessResult::allowedIfHasPermission($account, 'view countrylist entity');
    case 'update':
      return AccessResult::allowedIfHasPermission($account, 'edit countrylist entity');
    case 'delete':
      return AccessResult::allowedIfHasPermission($account, 'delete countrylist entity');
  }
  return AccessResult::neutral();
}