Save node body text html programatically in 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...

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!