Drupal 10: Pragmatically Generate A Node

This will generate an item of article content, authored by user 1.

$node = \Drupal\node\Entity\Node::create([
  'type' => 'article',
  'title' => 'Example Article',
  'body' => [
    'value' => '<p>Article text.</p>',
     'format' => filter_default_format()
   ],
   'uid' => 1,
]);
$node->save();

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
9 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.