Drupal 8 create node programmatically

  1. $user_id = \Drupal::currentUser()->id();
  2. $node = \Drupal\node\Entity\Node::create([
  3. 'type' => 'node_type',
  4. 'title' => 'test title',
  5. 'uid' => $user_id,
  6. //'status' => 0,
  7. ]);
  8. $node->save();
  9. Drupal::entityManager()->getViewBuilder('node')->resetCache();