class QueryPathEventSubscriber in Opigno module 8
Same name and namespace in other branches
- 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'
1 service uses QueryPathEventSubscriber
File
- src/
EventSubscriber/ QueryPathEventSubscriber.php, line 11
Namespace
Drupal\opigno_module\EventSubscriberView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
QueryPathEventSubscriber:: |
public | function | ||
QueryPathEventSubscriber:: |
static | function | Returns an array of event names this subscriber wants to listen to. |