class RedirectSubscriber in Open Social 8.7
Same name in this branch
- 8.7 modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber
- 8.7 modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber
- 8.7 modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber
- 8.7 modules/social_features/social_group/modules/social_group_quickjoin/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group_quickjoin\EventSubscriber\RedirectSubscriber
- 8.7 modules/social_features/social_group/modules/social_group_default_route/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group_default_route\EventSubscriber\RedirectSubscriber
- 8.7 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
- 8.9 modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber
- 8.6 modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber
- 8.8 modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber
- 10.3.x modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber
- 10.0.x modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber
- 10.1.x modules/social_features/social_search/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_search\EventSubscriber\RedirectSubscriber
- 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\EventSubscriberView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RedirectSubscriber:: |
protected | property | The config factory. | |
RedirectSubscriber:: |
protected | property | The current route. | |
RedirectSubscriber:: |
protected | property | The current user. | |
RedirectSubscriber:: |
protected | property | The request stack. | |
RedirectSubscriber:: |
public static | function | Get the request events. | |
RedirectSubscriber:: |
public | function | This method is called when the KernelEvents::REQUEST event is dispatched. | |
RedirectSubscriber:: |
public | function | Redirectsubscriber construct. |