Nov 13, 2019 in Drupal 8, Snippets

Where in drupal 7 you would typically use something like drupal_get_path_alias(), this is different in drupal 8. Below the code to get the curren alias of your route:

$path = \Drupal::service('path.current')->getPath();
$alias = \Drupal::service('path.alias_manager')->getAliasByPath($path);