You are here

protected function SliderAccessControlHandler::checkAccess in Image sliders 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/SliderAccessControlHandler.php, line 21

Class

SliderAccessControlHandler
Access controller for the slider entity.

Namespace

Drupal\image_slider

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 (\Drupal::currentUser()
    ->hasPermission($admin_permission)) {
    return AccessResult::allowed();
  }
  switch ($operation) {
    case 'view':
      return AccessResult::allowedIfHasPermission($account, 'view slider entity');
    case 'update':
      return AccessResult::allowedIfHasPermission($account, 'edit slider entity');
    case 'delete':
      return AccessResult::allowedIfHasPermission($account, 'delete slider entity');
  }
  return AccessResult::neutral();
}