You are here

public function RedirectSubscriber::redirectSearchWithPrefilledExposedFilters in Open Social 8.8

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

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_search/src/EventSubscriber/RedirectSubscriber.php, line 90

Class

RedirectSubscriber
Class RedirectSubscriber.

Namespace

Drupal\social_search\EventSubscriber

Code

public function redirectSearchWithPrefilledExposedFilters(GetResponseEvent $event) {
  $routeMatch = [
    'view.search_users.page_no_value',
    'view.search_users.page',
  ];
  if (!in_array($this->currentRoute
    ->getRouteName(), $routeMatch)) {
    return;
  }
  if ($this->requestStack
    ->getCurrentRequest() === NULL) {
    return;
  }
  $query = $this->requestStack
    ->getCurrentRequest()->query
    ->all();

  // Workaround for drupal.org issue #3085806.
  if (empty($query) || empty($query['created_op'])) {
    $query = [
      'created_op' => '<',
    ];
    $parameters = $this->currentRoute
      ->getParameters();
    $currentUrl = Url::fromRoute($this->currentRoute
      ->getRouteName());
    if (!empty($parameters
      ->get('keys'))) {
      $currentUrl = Url::fromRoute($this->currentRoute
        ->getRouteName(), [
        'keys' => $parameters
          ->get('keys'),
      ]);
    }
    $redirect_path = $currentUrl
      ->toString();
    $redirect = Url::fromUserInput($redirect_path, [
      'query' => $query,
    ]);
    $event
      ->setResponse(new RedirectResponse($redirect
      ->toString()));
  }
}