You are here

class RedirectSubscriber in Open Social 8.8

Same name in this branch
  1. 8.8 modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber
  2. 8.8 modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber
  3. 8.8 modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber
  4. 8.8 modules/social_features/social_group/modules/social_group_quickjoin/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group_quickjoin\EventSubscriber\RedirectSubscriber
  5. 8.8 modules/social_features/social_group/modules/social_group_default_route/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group_default_route\EventSubscriber\RedirectSubscriber
  6. 8.8 modules/social_features/social_group/modules/social_group_flexible_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group_flexible_group\EventSubscriber\RedirectSubscriber
Same name and namespace in other branches
  1. 8.9 modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber
  2. 8.6 modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber
  3. 8.7 modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber
  4. 10.3.x modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber
  5. 10.0.x modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber
  6. 10.1.x modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber
  7. 10.2.x modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber

Class RedirectSubscriber.

This class redirects the search pages with prefilled exposed filters because the bug in drupal.org issue #3085806.

@package Drupal\social_search\EventSubscriber

Hierarchy

  • class \Drupal\social_search\EventSubscriber\RedirectSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RedirectSubscriber

1 string reference to 'RedirectSubscriber'
social_search.services.yml in modules/social_features/social_search/social_search.services.yml
modules/social_features/social_search/social_search.services.yml
1 service uses RedirectSubscriber
social_search.redirect_subscriber in modules/social_features/social_search/social_search.services.yml
Drupal\social_search\EventSubscriber\RedirectSubscriber

File

modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php, line 23

Namespace

Drupal\social_search\EventSubscriber
View source
class RedirectSubscriber implements EventSubscriberInterface {

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The current route.
   *
   * @var \Drupal\Core\Routing\CurrentRouteMatch
   */
  protected $currentRoute;

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountProxy
   */
  protected $currentUser;

  /**
   * The request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

  /**
   * Redirectsubscriber construct.
   *
   * @param \Drupal\Core\Routing\CurrentRouteMatch $route_match
   *   The current route.
   * @param \Drupal\Core\Session\AccountProxy $current_user
   *   The current user.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config object.
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The request stack.
   */
  public function __construct(CurrentRouteMatch $route_match, AccountProxy $current_user, ConfigFactoryInterface $config_factory, RequestStack $request_stack) {
    $this->currentRoute = $route_match;
    $this->currentUser = $current_user;
    $this->configFactory = $config_factory;
    $this->requestStack = $request_stack;
  }

  /**
   * Get the request events.
   *
   * @return mixed
   *   Returns request events.
   */
  public static function getSubscribedEvents() {
    $events[KernelEvents::REQUEST][] = [
      'redirectSearchWithPrefilledExposedFilters',
    ];
    return $events;
  }

  /**
   * This method is called when the KernelEvents::REQUEST event is dispatched.
   *
   * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
   *   The event.
   */
  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()));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RedirectSubscriber::$configFactory protected property The config factory.
RedirectSubscriber::$currentRoute protected property The current route.
RedirectSubscriber::$currentUser protected property The current user.
RedirectSubscriber::$requestStack protected property The request stack.
RedirectSubscriber::getSubscribedEvents public static function Get the request events.
RedirectSubscriber::redirectSearchWithPrefilledExposedFilters public function This method is called when the KernelEvents::REQUEST event is dispatched.
RedirectSubscriber::__construct public function Redirectsubscriber construct.