You are here

public function EnrollRequestsOverviewSubscriber::checkAccessToEnrollRequestsOverview in Open Social 8.9

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_event/src/Routing/EnrollRequestsOverviewSubscriber.php \Drupal\social_event\Routing\EnrollRequestsOverviewSubscriber::checkAccessToEnrollRequestsOverview()
  2. 10.0.x modules/social_features/social_event/src/Routing/EnrollRequestsOverviewSubscriber.php \Drupal\social_event\Routing\EnrollRequestsOverviewSubscriber::checkAccessToEnrollRequestsOverview()
  3. 10.1.x modules/social_features/social_event/src/Routing/EnrollRequestsOverviewSubscriber.php \Drupal\social_event\Routing\EnrollRequestsOverviewSubscriber::checkAccessToEnrollRequestsOverview()
  4. 10.2.x modules/social_features/social_event/src/Routing/EnrollRequestsOverviewSubscriber.php \Drupal\social_event\Routing\EnrollRequestsOverviewSubscriber::checkAccessToEnrollRequestsOverview()

Check if the user is allowed to view this overview.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: The event.

File

modules/social_features/social_event/src/Routing/EnrollRequestsOverviewSubscriber.php, line 35

Class

EnrollRequestsOverviewSubscriber
Class RedirectSubscriber.

Namespace

Drupal\social_event\Routing

Code

public function checkAccessToEnrollRequestsOverview(GetResponseEvent $event) {
  $current_route = \Drupal::routeMatch()
    ->getRouteName();

  // First, lets check if the route matches.
  if ($current_route === 'view.event_manage_enrollment_requests.page_manage_enrollment_requests') {

    // Now lets get some stuff we need to perform some checks on.
    $current_event = social_event_get_current_event();
    if (!$current_event instanceof NodeInterface) {
      return;
    }

    // Now, lets check:
    // - If the current user has a permission to see the overview.
    // - If the current user is the owner/creator of this event.
    // - If the current user is an organiser/manager of this event.
    // And then allow access.
    if (social_event_manager_or_organizer()) {
      return;
    }

    // We deny the rest and send them to the front page.
    $event
      ->setResponse(new RedirectResponse(Url::fromRoute('entity.node.canonical', [
      'node' => $current_event
        ->id(),
    ])
      ->toString()));
  }
}