I created a custom content entity type dog using drush generate entity:content
.
When I go to www.example.com/dog/add, the page title (the one in the <title>
tag, not the <h1>
tag) is "Add dog". I want to change this to "Send a dog to outer space (and bring him back safely)".
It seems there is no place to set the title in the entity annotations, so I attempted to add an event subscriber:
dog/src/Routing/DogRouteSubscriber.php
class DogRouteSubscriber extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
if ($route = $collection->get('entity.dog.add_form')) {
$route->setDefault('_title', 'Send a dog to outer space (and bring him back safely)');
}
}
}
dog.services.yml
services:
dog.route_subscriber:
class: Drupal\dog\Routing\DogRouteSubscriber
tags:
- { name: event_subscriber }
I am using $route->setDefault('_title', 'Send a dog to outer space (and bring him back safely)'
based on code in this blog post, but even after rebuilding the cache, the page title isn't changed.
So: Where do I alter (or set) the entity add form's page title?
Similar but different questions:
- How can I change the page title? (general question about page titles)
- How can I change the title of the node/add page of a specific content type? (question about node content types, not custom entity types in general)