Oct 10, 2019 in Drupal 8, Snippets

Saving a link field is quite different from saving a text value in drupal 8. here's how its done.

$node = Node::create(
  'type' => 'page',
  'title' => 'My page',
  'link_field' => [
    'uri'=> 'https://example.com', 
    'title' => 'Visit the example website'
  ]
);
$node->save();