Getting a rewritten alias URL canonical entity URL (e.g. /my-alias/for-the-node) as string in modern Drupal is simple:
$entity->toUrl('canonical')->toString();Finding out how to get the "raw" unrewritten URL (e.g. /node/123) wasn't that easy:
$entity->toUrl('canonical', ['path_processing' => FALSE])->toString();Further documentation, especially for further options can be found here:


