By default, the user form title is the user's username which looks a little ugly if you're using the email registration module. In Drupal 7 I used to solve this problem using the title override module which is not ported do Drupal 8.

I would like to change the user form title to "Login details". Is this possible using a hook? If so: how do I do this?


The title override module utilizes drupal_set_title() to do this in Drupal 7. This function is deprecated in Drupal 8. The D8 equivalent here is to alter the _title_callback for the entity.user.edit_form route.

This is done by using an event subscriber to alter the RoutingEvents::ALTER event. This can be done through a custom module that:

  • Registering a new service class in mymodule.services.yml that is tagged with event_subscriber (see d.o. documentation example).
  • Defining the new service class to extend RouteSubscriberBase (see d.o. documentation example).
  • Implementing the alterRoutes(RouteCollection $collection) method within the service class to alter the entity.user.edit_form route (see example below).
  • A class/method that defines the title callback (see UserController::userTitle() as an example).

Within your route subscriber class:

   * {@inheritdoc}
  public function alterRoutes(RouteCollection $collection) {
    // Retrieve the user edit form route.
    if ($route = $collection->get('entity.user.edit_form')) {
      // Your module will need a controller class/method defined in
      // src/Controller/CustomUserController::userTitle
      // see core/modules/user/src/Controller/UserController.php to see how this
      // is implemented by default
  • I've just tested your approach and at this moment it causes me a white screen on the user edit page. – Vic Luijkx Oct 16 '16 at 21:15
  • This is my custom user controller at this moment: namespace Drupal\example\Controller; class CustomUserController extends ControllerBase { public function userTitle() { return array( '#type' => 'markup', '#markup' => t('Login details'), ); } } – Vic Luijkx Oct 16 '16 at 21:21
  • Without any specific error, all I could do is speculate what the problem might be. – Shawn Conn Oct 17 '16 at 0:09
  • Just found the mistake. I forgot adding the ControllerBase, my bad. It works brilliantly now! – Vic Luijkx Oct 17 '16 at 20:10

In drupal 8 you can hide the title block :


for the :

user/* pages 

Then create a block that display what you want for the

user/* pages 


It can also be dynamic if you create a view block with a contextual view displaying other user fields.


This doesnt allow dynamic information e.g. node title, node type - unless you use global functions for pulling the node from the url rather than as a parameter.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.