You are here

public function AddEnrolleeAccessCheck::access in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/modules/social_event_managers/src/Access/AddEnrolleeAccessCheck.php \Drupal\social_event_managers\Access\AddEnrolleeAccessCheck::access()
  2. 8.6 modules/social_features/social_event/modules/social_event_managers/src/Access/AddEnrolleeAccessCheck.php \Drupal\social_event_managers\Access\AddEnrolleeAccessCheck::access()
  3. 8.7 modules/social_features/social_event/modules/social_event_managers/src/Access/AddEnrolleeAccessCheck.php \Drupal\social_event_managers\Access\AddEnrolleeAccessCheck::access()
  4. 10.3.x modules/social_features/social_event/modules/social_event_managers/src/Access/AddEnrolleeAccessCheck.php \Drupal\social_event_managers\Access\AddEnrolleeAccessCheck::access()
  5. 10.0.x modules/social_features/social_event/modules/social_event_managers/src/Access/AddEnrolleeAccessCheck.php \Drupal\social_event_managers\Access\AddEnrolleeAccessCheck::access()
  6. 10.1.x modules/social_features/social_event/modules/social_event_managers/src/Access/AddEnrolleeAccessCheck.php \Drupal\social_event_managers\Access\AddEnrolleeAccessCheck::access()
  7. 10.2.x modules/social_features/social_event/modules/social_event_managers/src/Access/AddEnrolleeAccessCheck.php \Drupal\social_event_managers\Access\AddEnrolleeAccessCheck::access()

Checks access.

Parameters

\Symfony\Component\Routing\Route $route: The route to check against.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The parametrized route.

\Drupal\Core\Session\AccountInterface $account: The account to check access for.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

File

modules/social_features/social_event/modules/social_event_managers/src/Access/AddEnrolleeAccessCheck.php, line 34

Class

AddEnrolleeAccessCheck
Determines access to routes based on manage everything enrollments.

Namespace

Drupal\social_event_managers\Access

Code

public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
  $permission = $route
    ->getRequirement('_enrollee_permission');

  // Don't interfere if no permission was specified.
  // Or it's not the permission we are looking for.
  if ($permission === NULL || $permission !== 'manage everything enrollments') {
    return AccessResult::neutral();
  }

  // Don't interfere if no group was specified.
  $parameters = $route_match
    ->getParameters();
  if (!$parameters
    ->has('node')) {
    return AccessResult::neutral();
  }

  // Don't interfere if the group isn't a real group.
  $node = $parameters
    ->get('node');
  if (!is_null($node) && !$node instanceof Node) {
    $node = Node::load($node);
  }
  if (!$node instanceof NodeInterface) {
    return AccessResult::neutral();
  }

  // A user with this access can definitely do everything.
  if ($account
    ->hasPermission('manage everything enrollments')) {
    return AccessResult::allowed();
  }
  $type = $node
    ->getType();

  // Don't interfere if it's not an event.
  if ($type !== 'event') {
    return AccessResult::neutral();
  }

  // AN Users aren't allowed anything.
  if (!$account
    ->isAuthenticated()) {
    return AccessResult::forbidden();
  }

  // Lets return the correct access for our Event Manager.
  $managers_access = SocialEventManagersAccessHelper::getEntityAccessResult($node, 'update', $account);
  if ($managers_access instanceof AccessResultAllowed || $managers_access instanceof AccessResultForbidden) {
    return $managers_access
      ->addCacheableDependency($node);
  }

  // We allow it but lets add the group as dependency to the cache
  // now because field value might be edited and cache should
  // clear accordingly.
  return AccessResult::neutral();
}