My class derived from RouteSubscriberBase is not used

by Debbz   Last Updated March 18, 2016 08:03 AM - source

I would like to override the user login form in order to replace the username field with an email field.

I created a module (with EventSubscriber declared as service) and installed it. However, my class is not used load when I try to access to the user/login route. The call to exit() I use in my code doesn't display anything.

  /**
   * @file
   * Contains \Drupal\override_user\Routing\RouteSubscriber
   */

   namespace Drupal\override_user\Routing;

   use Drupal\Core\Routing\RouteSubscriberBase;
   use Symfony\Component\Routing\RouteCollection;

   /**
    * Listens to the dynamic route events.
    */
      class RouteSubscriber extends RouteSubscriberBase {

   /**
    * {@inheritdoc}
    */
    protected function alterRoutes(RouteCollection $collection) {
      if ($route = $collection->get('user.login')) {
         exit('user/login access');
         $route->setDefault('_form', '\Drupal\override_user\Form\MyUserLoginForm');
     }
    }
  }

My service

    services:
    route_subscriber:
        class: Drupal\override_user\Routing\RouteSubscriber
        tags: 
             - {name: event_subscriber }

What is wrong with my code?



Related Questions


Caching Event Subcriber

Updated March 13, 2016 08:03 AM

How can an event subscriber have access to entity type?

Updated November 17, 2017 23:07 PM


Event Subscriber Drupal8

Updated January 11, 2019 06:07 AM