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

As a part of the new New Symfony-based routing system, Drupal logic for generating a URL from a path or route needs to be integrated with the symfony HttpKernel.

Drupal 7

<?php
  $url
= url($path, $options);
?>

Drupal 8

The case of creating a URL from a route name:

<?php
  $generator
= Drupal::urlGenerator();
 
$route_name = 'test_1';
 
$url = $generator->generate($route_name);
?>

The case of generating a URL from a route name with parameters. The route may require parameters to build the URL, depending on the path pattern

<?php
  $generator
= Drupal::urlGenerator();
 
$url = $generator->generate('user_edit', array('user'  => '99'));
?>

note, the pattern for this route is /user/{user}

The case of getting the Drupal path corresponding to a route name when you need to interact with code still using the Drupal paths:

<?php
  $generator
= Drupal::urlGenerator();
 
$route_name = 'test_1';
 
$path = $generator->getPathFromRoute($route_name);
?>

Note that the generator is available from the DIC as 'url_generator'. A global helper method is available at Drupal::urlGenerator(). which simply pulls the object from the container.

Using routes is recommended. Paths are deprecated, but for situations still using paths, it is possible to create a URL from a Drupal path:

<?php
  $generator
= Drupal::urlGenerator();
 
$url = $generator->generateFromPath($path, $options);
?>
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