When I get the title on some pages, I get an empty title, Ex: "Home", "admin/content". The code I am using in my subscriber is the following one:

class ExampleSubscriber implements EventSubscriberInterface {
  public static function getSubscribedEvents() {
    $events[KernelEvents::REQUEST][] = array('onResponse', 0);
    return $events;
  }

  public function onResponse($event) {
    $request = \Drupal::request();
    $route_match = \Drupal::routeMatch();
    $title = \Drupal::service('title_resolver')->getTitle($request, $route_match->getRouteObject());
  }
}

Comments

swentel’s picture

Status: Active » Closed (duplicate)

See #2264043: Add back a simple page title getter for more information regarding this problem.