public function HandlerFor403AccessDenied::on403 in moderated content bulk publish 8
Same name and namespace in other branches
- 2.0.x src/EventSubscriber/HandlerFor403AccessDenied.php \Drupal\moderated_content_bulk_publish\EventSubscriber\HandlerFor403AccessDenied::on403()
- 1.0.x src/EventSubscriber/HandlerFor403AccessDenied.php \Drupal\moderated_content_bulk_publish\EventSubscriber\HandlerFor403AccessDenied::on403()
File
- src/
EventSubscriber/ HandlerFor403AccessDenied.php, line 23
Class
Namespace
Drupal\moderated_content_bulk_publish\EventSubscriberCode
public function on403(GetResponseForExceptionEvent $event) {
$request = $event
->getRequest();
$is_anonymous = $this->currentUser
->isAnonymous();
$route_name = $request->attributes
->get('_route');
$is_not_login = $route_name != 'user.login';
$current_path = \Drupal::service('path.current')
->getPath();
if (stripos($current_path, 'latest') > 1 && stripos($current_path, 'ode') > 0) {
$langId = \Drupal::languageManager()
->getCurrentLanguage()
->getId();
$new_path = $current_path;
// Fait de la magique ici.
// Latest revision doesn't exist in this language, redirect to node page.
$new_path = str_replace('/latest', '', $current_path);
\Drupal::logger('moderated_content_bulk_publish')
->notice(utf8_encode('HandlerFor403AccessDenied: Redirecting from ' . $current_path . ' to ' . $new_path));
$base_url = \Drupal::request()
->getSchemeAndHttpHost();
$returnResponse = new \Drupal\Core\Routing\TrustedRedirectResponse($base_url . '/' . $langId . $new_path);
// TODO: figure out how to do this the Drupal 8 way for internal path but didn't because of language afterthought in Drupal 8.
$event
->setResponse($returnResponse);
return;
}
}