Creating a link from node ID in Drupal 8
Asked 07 September, 2021
Viewed 1.3K times
  • 59
Votes

I am checking out Drupal 8 and try to generate a link based on the node ID of an article. In Drupal 7 it is something like:

$options = array('absolute' => TRUE);
$nid = 1; // Node ID
$url = url('node/' . $nid, $options);

This results into an absolute link with the correct url-alias.

So the url()-function seems to be deprecated; what is the Drupal-8 way? Looks like a really basic function for me but I could not find any useful references.

9 Answer