Programmatically set URL Alias when creating node in form plugin I'm currently importing data from a database to create nodes based on them. My node save code looks like this

$node = \Drupal\node\Entity\Node::create([
        'type'                 =&gt; 'issue',
        'title'                =&gt; $title,
        'body'                 =&gt; $body,
        'field_issue_category' =&gt; $term,
        'field_issue_type'     =&gt; 'publication',
        'field_pub_id'         =&gt; [
            'target_id'           =&gt; $publication_id,
        ],
        'field_issue_group' =&gt; $group_id,
        'field_date'        =&gt; $date,
    ]);
$node-&gt;save();


I also want to create a url alias based on the title of this node, which I create like this,

$nid       = $node-&gt;id();
$title     = preg_replace("/[\s_]/", "-", $title);
$path      = \Drupal::service('path.alias_storage')-&gt;save('/node/'.$nid, '/mypath/'.$title);


This successfully create a url alias that shows up in the URL aliases list in the URL alias config. However it doesn't show up in the URL alias field on the node edit page. 



This creates a problem. One, the user can't see what the actual alias is. 
Also I have a block plugin that puts every node of that type in a list on a page. It also displays the url to that node. I'd like the url displayed to be the alias like '/mypath/title' but Drupal only seems to know about the '/node/nid' path.

Is there a proper way to programmatically set a nodes url alias so that it still appears in the url alias field?
The node widget currently only shows aliases that have the same langcode as the node. https://www.drupal.org/node/2511968 will change that and also display aliases without a specific language.

But if the alias also doesn't work on the site then that sounds like something else also isn't correct yet. Does it work in that block if you create an alias manually in the UI? If so, compare the two records in the url_alias table, do you see a difference?

You can create an alias as part of saving the node, there is a path pseudo/computed field. Try adding this to your array:

'path' =&gt; [
  'alias' =&gt; '/mypath/' . $title,
  'pathauto' =&gt; PathautoState::SKIP,
]


That should create the alias correctly as well.

And last, if your alias is so predictable, you should look at Pathauto. That allows you to set up rules for creating aliases. Among other things, it has a ton of logic to deal with special characters and duplicates, your code will have a problem if you have two nodes with the same title, for example.