I want to redirect every users page to front page? like if user page url is /user/97 then it redirect to front page if user is not administrator. I want user page inaccessible to other users but only administrators.
How can I achieve this?
I tried doing like this:
<?php namespace Drupalmyisu_ubitRouting; use DrupalCoreRoutingRouteSubscriberBase; use SymfonyComponentRoutingRouteCollection; // use DrupaluserEntityUser; /** * Listens to the dynamic route events. */ class RouteSubscriber extends RouteSubscriberBase { /** * {@inheritdoc} */ protected function alterRoutes(RouteCollection $collection) { // Change the route associated with the user profile page (/user, /user/{uid}). if ($route = $collection->get('user.page')) { $route->setPath('/'); } } }
module.services.yml:
services: user_profile.route_subscriber: class: DrupalmoduleRoutingRouteSubscriber tags: - { name: event_subscriber }
What am I doing wrong here?