Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

For all Drupal 8 code going forward, if you need access to the request parameters, the route name, or the route object itself, use RouteMatch.

  • If you have a request available, you can just RouteMatch::createFromRequest($request).
  • Without a request, you should inject the 'current_route_match' service.
  • In procedural code, you can use \Drupal::routeMatch().

For example:

D7

if ($node = menu_get_object('node', 1)) {
}

D8

if ($node = \Drupal::routeMatch()->getParameter('node')) {
}

For Drupal 7 to Drupal 8 conversion information related to routing and route parameters, see the following other change records:

Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done