Generate node edit link I'm attempting to dynamically generate a node edit link. I understand that I can manually create it by using

$editpath = '/node/'.$nid.'/edit';

but I have multiple sites that use subfolders like 


  /site1_subfolder/node/123/edit


and


  /site2_subfolder/node/123/edit


I looked at the node class and I couldn't see any method that would generate this link for me. I did see that there's a NodeForm class but I didn't see any static methods I could take advantage of either. 

Given a node or node id is there a way to generate an admin edit link to its edit form?

NOTE: If that's not possible I would be fine with using a function to get the subfolder names so I could do $editpath = '/'.$subfolder_name.'/node/'.$nid.'/edit';

But I'm not sure how to do that either.

UPDATE: I suppose I could do a $node->toUrl()->toString() to get the direct path and add edit at the end but this would only give me the alias, is there a way to not get the alias from this and get the direct link to the node instead?
Given a node or node id is there a way to generate an admin edit link to its edit form?


Absolutely, the Url class has a fromRoute method:

$url = Url::fromRoute('entity.node.edit_form', ['node' =&gt; $nid]);
$link = Link::fromTextAndUrl('edit', $url);
$build = [
  ...
  'link' =&gt; $link-&gt;toRenderable(),
];