Goal: To send an email with a list of URLs generated from nodes.
In my custom module I have managed to get the node id which the user wants and I now want to get the URL of each node to put into my email.
I searched the db and used google but I can't seem to find the right solution.
It seems we need to construct the URL something like this:
<?php global $base_url; $link=$base_url."// few more parameters
Consider the following: $node = \Drupal::routeMatch()->getParameter('node'); if ($node instanceof \Drupal\node\NodeInterface) { $nid = $node->id(); // Do whatever you need to do with the node ID here... }
You can use the url()
function:
$options = array('absolute' => TRUE); $nid = 1; // Node ID $url = url('node/' . $nid, $options);
That will give you the absolute path (i.e. with http://example.com/ in front of it), with the URL aliased path to the node page.
You can also try drupal_lookup_path('alias',"node/".$node->nid)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With