Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. class FacultyStaffRedirectSubscriber implements EventSubscriberInterface {
  2.  
  3.  
  4. public function checkForRedirection(GetResponseEvent $event) {
  5. $request = Drupal::request();
  6. $requestUrl = Drupal::service('path.current')->getPath();
  7. $current_user = Drupal::currentUser();
  8. $roles = $current_user->getRoles();
  9.  
  10. if ($requestUrl == '/faculty-staff') {
  11. if (
  12. !in_array('faculty', $roles) ||
  13. !in_array('staff', $roles)
  14. ) {
  15.  
  16. $path = '/404';
  17. $response = new RedirectResponse($path);
  18. $response->send();
  19. return;
  20. }
  21. }
  22. }
  23. public static function getSubscribedEvents() {
  24. $events[KernelEvents::REQUEST][] = array('checkForRedirection');
  25. return $events;
  26. }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement