public function ResponseSubscriber::onResponse in Moderation Dashboard 8
Same name and namespace in other branches
- 2.0.x src/Routing/ResponseSubscriber.php \Drupal\moderation_dashboard\Routing\ResponseSubscriber::onResponse()
Redirects user login to the Moderation Dashboard, when appropriate.
Parameters
\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event: The response event.
File
- src/
Routing/ ResponseSubscriber.php, line 63
Class
- ResponseSubscriber
- Response subscriber to redirect user login to the Moderation Dashboard.
Namespace
Drupal\moderation_dashboard\RoutingCode
public function onResponse(FilterResponseEvent $event) {
$response = $event
->getResponse();
$request = $event
->getRequest();
$should_redirect = $this->configFactory
->get('moderation_dashboard.settings')
->get('redirect_on_login');
if ($should_redirect && $response instanceof RedirectResponse) {
$response_url_components = UrlHelper::parse($response
->getTargetUrl());
$has_destination = isset($response_url_components['query']['destination']);
$is_login = $request->request
->get('form_id') === 'user_login_form';
$has_permission = $this->currentUser
->hasPermission('use moderation dashboard');
$has_moderated_content_type = $this->conditionManager
->createInstance('has_moderated_content_type')
->execute();
if ($has_permission && $is_login && $has_moderated_content_type && !$has_destination) {
$url = Url::fromRoute('page_manager.page_view_moderation_dashboard_moderation_dashboard-panels_variant-0', [
'user' => $this->currentUser
->id(),
]);
$response
->setTargetUrl($url
->toString());
}
}
}