You are here

class QueryPathEventSubscriber in Opigno module 8

Same name and namespace in other branches
  1. 3.x src/EventSubscriber/QueryPathEventSubscriber.php \Drupal\opigno_module\EventSubscriber\QueryPathEventSubscriber

Hierarchy

  • class \Drupal\opigno_module\EventSubscriber\QueryPathEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of QueryPathEventSubscriber

1 string reference to 'QueryPathEventSubscriber'
opigno_module.services.yml in ./opigno_module.services.yml
opigno_module.services.yml
1 service uses QueryPathEventSubscriber
opigno_module.event_subscriber in ./opigno_module.services.yml
Drupal\opigno_module\EventSubscriber\QueryPathEventSubscriber

File

src/EventSubscriber/QueryPathEventSubscriber.php, line 11

Namespace

Drupal\opigno_module\EventSubscriber
View source
class QueryPathEventSubscriber implements EventSubscriberInterface {

  // Remember query string (with table sort) as session variable and reload page with it
  public function checkRedirection(FilterResponseEvent $event) {

    // Add new routes for enable logic
    $available_routes = [
      'entity.opigno_activity.collection',
      'entity.opigno_module.collection',
      'entity.group.collection',
    ];
    $route = \Drupal::routeMatch();
    $session = \Drupal::request()
      ->getSession();
    if (in_array($route
      ->getRouteName(), $available_routes)) {
      $param = \Drupal::request()->query
        ->all();

      // If we have an empty page (without new query params), we load previous one
      if (empty($param)) {
        $order_values = $session
          ->get($route
          ->getRouteName());
        if (!empty($order_values)) {
          $url = Url::fromRoute($route
            ->getRouteName());
          $url
            ->setOption('query', $order_values);
          $response = new RedirectResponse($url
            ->toString());
          $event
            ->setResponse($response);
        }
      }
      else {
        $session
          ->set($route
          ->getRouteName(), $param);
      }
    }
  }
  static function getSubscribedEvents() {
    $events[KernelEvents::RESPONSE][] = [
      'checkRedirection',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
QueryPathEventSubscriber::checkRedirection public function
QueryPathEventSubscriber::getSubscribedEvents static function Returns an array of event names this subscriber wants to listen to.