By tim.plunkett on
Change record status:
Published (View all published change records)
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