Redirect.php in Open Social 8.8
Same filename and directory in other branches
- 8.9 modules/custom/social_gdpr/src/Subscriber/Redirect.php
- 8.2 modules/custom/social_gdpr/src/Subscriber/Redirect.php
- 8.3 modules/custom/social_gdpr/src/Subscriber/Redirect.php
- 8.4 modules/custom/social_gdpr/src/Subscriber/Redirect.php
- 8.5 modules/custom/social_gdpr/src/Subscriber/Redirect.php
- 8.6 modules/custom/social_gdpr/src/Subscriber/Redirect.php
- 8.7 modules/custom/social_gdpr/src/Subscriber/Redirect.php
- 10.0.x modules/custom/social_gdpr/src/Subscriber/Redirect.php
- 10.1.x modules/custom/social_gdpr/src/Subscriber/Redirect.php
Namespace
Drupal\social_gdpr\SubscriberFile
modules/custom/social_gdpr/src/Subscriber/Redirect.phpView source
<?php
namespace Drupal\social_gdpr\Subscriber;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* Class Redirect.
*
* @package Drupal\social_gdpr\Subscriber
*/
class Redirect implements EventSubscriberInterface {
/**
* The current active route match object.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* RedirectSubscriber constructor.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current active route match object.
* @param \Drupal\Core\Session\AccountProxyInterface $current_user
* The current user.
*/
public function __construct(RouteMatchInterface $route_match, AccountProxyInterface $current_user) {
$this->routeMatch = $route_match;
$this->currentUser = $current_user;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = [
'checkForRedirection',
];
return $events;
}
/**
* This method is called when the KernelEvents::REQUEST event is dispatched.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The event.
*/
public function checkForRedirection(GetResponseEvent $event) {
if ($this->routeMatch
->getRouteName() != 'entity.data_policy.version_history') {
return;
}
if ($this->currentUser
->id() == 1 || !$this->currentUser
->hasPermission('view all data policy revisions')) {
return;
}
$url = Url::fromRoute('social_gdpr.data_policy.revisions');
$response = new RedirectResponse($url
->toString());
$event
->setResponse($response);
}
}