Create a node programmatically in Drupal 8

Submitted by editor on Fri, 11/13/2015 - 12:00

How to create a node programmatically in Drupal 8 ?

Here an example for create node programmatically in Drupal 8

Node type : article
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$node = \Drupal\node\Entity\Node::create(array(
          'type' => 'article',
          'title' => 'The title',
          'langcode' => $language,
          'uid' => 1,
          'status' => 1,
          'body' => array('The body text'),
          'field_date' => array("2000-01-30"),
            //'field_fields' => array('Custom values'), // Add your custon field values like this



john (not verified)

Sat, 05/21/2016 - 17:55

PHP Fatal error:  Call to undefined function Drupal\file\Plugin\Field\FieldType\file_default_scheme() in core/modules/file/src/Plugin/Field/FieldType/FileItem.php on line 39

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.