May 18, 2018 in Snippets, Drupal 8

When saving nodes programmatically, you probably want to set the body to accept html. it is important to set the input format, so html is accepted. With the snippet below, it works fine. 

$node->set('body', $tweettext);
$node->body->format = 'full_html';
$node->save(); // save etc...