class HandlerFor403AccessDenied 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
- 1.0.x src/EventSubscriber/HandlerFor403AccessDenied.php \Drupal\moderated_content_bulk_publish\EventSubscriber\HandlerFor403AccessDenied
Hierarchy
- class \Drupal\Core\EventSubscriber\HttpExceptionSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\moderated_content_bulk_publish\EventSubscriber\HandlerFor403AccessDenied
Expanded class hierarchy of HandlerFor403AccessDenied
1 string reference to 'HandlerFor403AccessDenied'
1 service uses HandlerFor403AccessDenied
File
- src/
EventSubscriber/ HandlerFor403AccessDenied.php, line 11
Namespace
Drupal\moderated_content_bulk_publish\EventSubscriberView source
class HandlerFor403AccessDenied extends HttpExceptionSubscriberBase {
protected $currentUser;
public function __construct(AccountInterface $current_user) {
$this->currentUser = $current_user;
}
protected function getHandledFormats() {
return [
'html',
];
}
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;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HandlerFor403AccessDenied:: |
protected | property | ||
HandlerFor403AccessDenied:: |
protected | function |
Specifies the request formats this subscriber will respond to. Overrides HttpExceptionSubscriberBase:: |
|
HandlerFor403AccessDenied:: |
public | function | ||
HandlerFor403AccessDenied:: |
public | function | ||
HttpExceptionSubscriberBase:: |
protected static | function | Specifies the priority of all listeners in this class. | 4 |
HttpExceptionSubscriberBase:: |
public static | function | Registers the methods in this class that should be listeners. | |
HttpExceptionSubscriberBase:: |
public | function | Handles errors for this subscriber. |