Create node Programatically in Drupal 8

Public
</> CopyGet raw version
php
  1. $node = entity_create('node', array(
  2. 'type' => 'article',
  3. 'title' => $form_state->getValue('title'),
  4. 'body' => array(
  5. 'value' => $form_state->getValue('body'),
  6. 'format' => 'basic_html',
  7. ),
  8. 'uid' => $uid,
  9. ));
  10. $node->save();