Skip to main content
1 of 3
J-P
  • 485
  • 1
  • 6
  • 8

Note: The accepted response for this question is out of date: see this change record for best practice.

You should use the CurrentRouteMatch service to retrieve the current route, and then read or modify its parameters. This wraps any Symfony etc. magic.

In procedural code, you would write:

<?php

$route = \Drupal::routeMatch()->getCurrentRouteMatch()
  ->getRouteObject();
$title = $route->getDefault('_title');

In object-oriented code, you should implement dependency injection and inject the service current_route_match (this is what \Drupal::routeMatch() class does internally anyway.)

J-P
  • 485
  • 1
  • 6
  • 8