Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FacultyStaffRedirectSubscriber implements EventSubscriberInterface {
- public function checkForRedirection(GetResponseEvent $event) {
- $request = Drupal::request();
- $requestUrl = Drupal::service('path.current')->getPath();
- $current_user = Drupal::currentUser();
- $roles = $current_user->getRoles();
- if ($requestUrl == '/faculty-staff') {
- if (
- !in_array('faculty', $roles) ||
- !in_array('staff', $roles)
- ) {
- $path = '/404';
- $response = new RedirectResponse($path);
- $response->send();
- return;
- }
- }
- }
- public static function getSubscribedEvents() {
- $events[KernelEvents::REQUEST][] = array('checkForRedirection');
- return $events;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement