You are here

class Redirect in Open Social 8.4

Same name and namespace in other branches
  1. 8.9 modules/custom/social_gdpr/src/Subscriber/Redirect.php \Drupal\social_gdpr\Subscriber\Redirect
  2. 8.2 modules/custom/social_gdpr/src/Subscriber/Redirect.php \Drupal\social_gdpr\Subscriber\Redirect
  3. 8.3 modules/custom/social_gdpr/src/Subscriber/Redirect.php \Drupal\social_gdpr\Subscriber\Redirect
  4. 8.5 modules/custom/social_gdpr/src/Subscriber/Redirect.php \Drupal\social_gdpr\Subscriber\Redirect
  5. 8.6 modules/custom/social_gdpr/src/Subscriber/Redirect.php \Drupal\social_gdpr\Subscriber\Redirect
  6. 8.7 modules/custom/social_gdpr/src/Subscriber/Redirect.php \Drupal\social_gdpr\Subscriber\Redirect
  7. 8.8 modules/custom/social_gdpr/src/Subscriber/Redirect.php \Drupal\social_gdpr\Subscriber\Redirect
  8. 10.0.x modules/custom/social_gdpr/src/Subscriber/Redirect.php \Drupal\social_gdpr\Subscriber\Redirect
  9. 10.1.x modules/custom/social_gdpr/src/Subscriber/Redirect.php \Drupal\social_gdpr\Subscriber\Redirect

Class Redirect.

@package Drupal\social_gdpr\Subscriber

Hierarchy

  • class \Drupal\social_gdpr\Subscriber\Redirect implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of Redirect

1 string reference to 'Redirect'
social_gdpr.services.yml in modules/custom/social_gdpr/social_gdpr.services.yml
modules/custom/social_gdpr/social_gdpr.services.yml
1 service uses Redirect
social_gdpr.redirect_subscriber in modules/custom/social_gdpr/social_gdpr.services.yml
Drupal\social_gdpr\Subscriber\Redirect

File

modules/custom/social_gdpr/src/Subscriber/Redirect.php, line 18

Namespace

Drupal\social_gdpr\Subscriber
View source
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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Redirect::$currentUser protected property The current user.
Redirect::$routeMatch protected property The current active route match object.
Redirect::checkForRedirection public function This method is called when the KernelEvents::REQUEST event is dispatched.
Redirect::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
Redirect::__construct public function RedirectSubscriber constructor.