Create a link form api Drupal 8

use Drupal\Core\Url;
$nid = 23   // node id you want to open
$url = Url::fromRoute('entity.node.edit_form', ['node' => 23],['query' => ['key' => 'value']]);  //get the route name from module.routing.yml file
$form['link'] = array(
'#type' => 'link',
'#title' => 'open link',
'#url' => $url,
);

This will generate below html

<a href="/node/23/edit?key=value" data-drupal-selector="edit-link" id="edit-link">open link</a>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s