public function ResponseSubscriber::onResponse in Moderation Dashboard 2.0.x
Same name and namespace in other branches
- 8 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.
Throws
\Drupal\Component\Plugin\Exception\PluginException
File
- src/
Routing/ ResponseSubscriber.php, line 65
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('view.moderation_dashboard.page_1', [
'user' => $this->currentUser
->id(),
]);
$response
->setTargetUrl($url
->toString());
}
}
}