public function RedirectSubscriber::checkForRedirection in Open Social 8.9
Same name in this branch
- 8.9 modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber::checkForRedirection()
- 8.9 modules/social_features/social_group/modules/social_group_flexible_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group_flexible_group\EventSubscriber\RedirectSubscriber::checkForRedirection()
Same name and namespace in other branches
- 8 modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber::checkForRedirection()
- 8.2 modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber::checkForRedirection()
- 8.3 modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber::checkForRedirection()
- 8.4 modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber::checkForRedirection()
- 8.5 modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber::checkForRedirection()
- 8.6 modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber::checkForRedirection()
- 8.7 modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber::checkForRedirection()
- 8.8 modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber::checkForRedirection()
- 10.3.x modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber::checkForRedirection()
- 10.0.x modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber::checkForRedirection()
- 10.1.x modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber::checkForRedirection()
- 10.2.x modules/social_features/social_group/src/EventSubscriber/RedirectSubscriber.php \Drupal\social_group\EventSubscriber\RedirectSubscriber::checkForRedirection()
This method is called when the KernelEvents::REQUEST event is dispatched.
Parameters
\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: The event.
File
- modules/
social_features/ social_group/ src/ EventSubscriber/ RedirectSubscriber.php, line 35
Class
- RedirectSubscriber
- Class RedirectSubscriber.
Namespace
Drupal\social_group\EventSubscriberCode
public function checkForRedirection(GetResponseEvent $event) {
// Check if there is a group object on the current route.
$group = _social_group_get_current_group();
// Get the current route name for the checks being performed below.
$routeMatch = \Drupal::routeMatch()
->getRouteName();
// Redirect the group content collection index to the group canonical URL.
if ($routeMatch === 'entity.group_content.collection') {
$event
->setResponse(new RedirectResponse(Url::fromRoute('entity.group.canonical', [
'group' => $group
->id(),
])
->toString()));
}
// Get the current user.
$user = \Drupal::currentUser();
// The array of forbidden routes.
$routes = [
'entity.group.canonical',
'entity.group.join',
'view.group_events.page_group_events',
'view.group_topics.page_group_topics',
];
// If a group is set, and the type is closed_group.
if ($group && $group
->getGroupType()
->id() == 'closed_group') {
if ($user
->id() != 1) {
if ($user
->hasPermission('manage all groups')) {
return;
}
elseif (!$group
->getMember($user) && in_array($routeMatch, $routes)) {
$event
->setResponse(new RedirectResponse(Url::fromRoute('view.group_information.page_group_about', [
'group' => $group
->id(),
])
->toString()));
}
}
}
}