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
$route->setDefault('_title_callback','Drupal\mymodule\Controller\CustomUserController::userTitle');
}
}