I need to override the UserController to to change logout redirection, I try thiscode below to test my new controller but my display test inside doesn't work. :

namespace Drupal\my_module\Controller;

use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

class MyModuleUserController extends ControllerBase {

  * Constructs a MyModuleUserController object.
  public function __construct() {}

  * {@inheritdoc}
  public static function create(ContainerInterface $container) {
    return new static();

  * Logs the current user out.
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   A redirection to home page.
  public function logout() {
    echo "<pre>";
    echo "<h1>test controller</h1>";
    exit(0) //@TODO delete this test
    return $this->redirect('user.login');

Path : my_module/src/Controller/UserControler/MyModuleUserController.php

  • 1
    You need an event subscriber to override the user module's logout route. There's an example here: drupal.stackexchange.com/questions/187585/… – Clive Oct 23 '17 at 14:07
  • I try your suggestion with a new file routeSubscriber.php and :services: my_module.route_subscriber: class: Drupal\my_module\Routing\RouteSubscriber tags: - { name: event_subscriber } but I'm in the fog to debug that. – florian_drupal Oct 23 '17 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.