You are here

public function RedirectSubscriber::profileLandingPage in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber::profileLandingPage()
  2. 8.5 modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber::profileLandingPage()
  3. 8.6 modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber::profileLandingPage()
  4. 8.7 modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber::profileLandingPage()
  5. 8.8 modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber::profileLandingPage()
  6. 10.0.x modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber::profileLandingPage()
  7. 10.1.x modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber::profileLandingPage()
  8. 10.2.x modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber::profileLandingPage()

This method is called when the KernelEvents::REQUEST event is dispatched.

Parameters

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

File

modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php, line 77

Class

RedirectSubscriber
Class RedirectSubscriber.

Namespace

Drupal\social_user\EventSubscriber

Code

public function profileLandingPage(GetResponseEvent $event) {

  // First check if the current route is the group canonical.
  $routeMatch = $this->currentRoute
    ->getRouteName();

  // Not group canonical, then we leave.
  if ($routeMatch !== 'entity.user.canonical') {
    return;
  }

  // Fetch the user parameter and check if's an actual user.
  $user = $this->currentRoute
    ->getParameter('user');

  // Not user, then we leave.
  if (!$user instanceof User) {
    return;
  }

  // Set the already default redirect route.
  $defaultRoute = 'social_user.stream';

  // Fetch the settings.
  $settings = $this->configFactory
    ->get('social_user.settings');

  // Check there is a custom route set.
  if ($this->currentUser
    ->id() !== $user
    ->id()) {
    $route = $settings
      ->get('social_user_profile_landingpage');
  }

  // Still no route here? Then we use the normal default.
  if (!isset($route)) {
    $route = $defaultRoute;
  }

  // Determine the URL we want to redirect to.
  $url = Url::fromRoute($route, [
    'user' => $user
      ->id(),
  ]);

  // If it's not set, set to canonical, or the current user has no access.
  if (!isset($route) || $route === $routeMatch || $url
    ->access($this->currentUser) === FALSE) {

    // This basically means that the normal flow remains intact.
    return;
  }

  // Redirect.
  $event
    ->setResponse(new RedirectResponse($url
    ->toString()));
}