Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Create a node programmatically in Drupal 8

By editor , 13 November, 2015
Question

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
    ));
$node->save();

 

Tags

  • Drupal 8
  • Code
  • Node
  • Add new comment

Comments2

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

john (not verified)

10 years 6 months ago

PHP Fatal error:  Call to…

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

  • Reply

editor

10 years 6 months ago

In reply to PHP Fatal error:  Call to… by john (not verified)

Please send me your codes…

Please send me your codes and full details.

  • Reply

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer