You are here

protected function LatestActivityAccessControlHandler::checkAccess in Opigno Learning path 3.x

Same name and namespace in other branches
  1. 8 src/LatestActivityAccessControlHandler.php \Drupal\opigno_learning_path\LatestActivityAccessControlHandler::checkAccess()

Entity access control. checkAccess is called with the $operation as defined in the routing.yml file.

Overrides EntityAccessControlHandler::checkAccess

File

src/LatestActivityAccessControlHandler.php, line 23

Class

LatestActivityAccessControlHandler
Access control handler for the opigno_latest_group_activity entity.

Namespace

Drupal\opigno_learning_path

Code

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

  /** @var \Drupal\opigno_learning_path\LatestActivityInterface $entity */

  // LatestActivity entity only used internally to track a latest activity
  // in trainings for the latest_active_trainings view.
  // Deny all edit operations to all users.
  // Allow view if the user is a member of the related training.
  if ($operation === 'view') {
    $training = $entity
      ->getTraining();
    $is_member = isset($training) && $training
      ->getMember($account);
    return AccessResult::allowedIf($is_member);
  }

  // Unknown operation, return neutral
  // (will be denied if all access control handlers return neutral).
  return AccessResult::neutral();
}