class RedirectSubscriber in Open Social 8.5
Same name in this branch
- 8.5 modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber
- 8.5 modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber
- 8.5 modules/social_features/social_group/modules/social_group_quickjoin/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group_quickjoin\EventSubscriber\RedirectSubscriber
- 8.5 modules/social_features/social_group/modules/social_group_default_route/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group_default_route\EventSubscriber\RedirectSubscriber
Same name and namespace in other branches
- 8.9 modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber
- 8.6 modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber
- 8.7 modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber
- 8.8 modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber
- 10.3.x modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber
- 10.0.x modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber
- 10.1.x modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber
- 10.2.x modules/social_features/social_user/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_user\EventSubscriber\RedirectSubscriber
Class RedirectSubscriber.
@package Drupal\social_user\EventSubscriber
Hierarchy
- class \Drupal\social_user\EventSubscriber\RedirectSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of RedirectSubscriber
1 string reference to 'RedirectSubscriber'
- social_user.services.yml in modules/
social_features/ social_user/ social_user.services.yml - modules/social_features/social_user/social_user.services.yml
1 service uses RedirectSubscriber
- social_user.redirect_subscriber in modules/
social_features/ social_user/ social_user.services.yml - Drupal\social_user\EventSubscriber\RedirectSubscriber
File
- modules/
social_features/ social_user/ src/ EventSubscriber/ RedirectSubscriber.php, line 20
Namespace
Drupal\social_user\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;
/**
* 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.
*/
public function __construct(CurrentRouteMatch $route_match, AccountProxy $current_user, ConfigFactoryInterface $config_factory) {
$this->currentRoute = $route_match;
$this->currentUser = $current_user;
$this->configFactory = $config_factory;
}
/**
* Get the request events.
*
* @return mixed
* Returns request events.
*/
public static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = [
'profileLandingPage',
];
return $events;
}
/**
* This method is called when the KernelEvents::REQUEST event is dispatched.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The event.
*/
public function profileLandingPage(GetResponseEvent $event) {
// First check if the current route is the group canonical.
$routeMatch = $this->currentRoute
->getRouteName();
// Not group canonical, then we leave.
if ($routeMatch !== 'entity.user.canonical') {
return;
}
// Fetch the user parameter and check if's an actual user.
$user = $this->currentRoute
->getParameter('user');
// Not user, then we leave.
if (!$user instanceof User) {
return;
}
// Set the already default redirect route.
$defaultRoute = 'social_user.stream';
// Fetch the settings.
$settings = $this->configFactory
->get('social_user.settings');
// Check there is a custom route set.
if ($this->currentUser
->id() !== $user
->id()) {
$route = $settings
->get('social_user_profile_landingpage');
}
// Still no route here? Then we use the normal default.
if (!isset($route)) {
$route = $defaultRoute;
}
// Determine the URL we want to redirect to.
$url = Url::fromRoute($route, [
'user' => $user
->id(),
]);
// If it's not set, set to canonical, or the current user has no access.
if (!isset($route) || $route === $routeMatch || $url
->access($this->currentUser) === FALSE) {
// This basically means that the normal flow remains intact.
return;
}
// Redirect.
$event
->setResponse(new RedirectResponse($url
->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:: |
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. |