Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

In Drupal 8, the node is an entity. The Drupal core class Node will provide us to create or update the nodes in Drupal 8. The below is an example of creating a node Drupal 8.

Example : 


use Drupal\node\Entity\Node;

* add Node
$node = Node::create(['type' => $contentType]);
    $node->langcode = "fr";
    $node->uid = 1;
    $node->promote = 0;
    $node->sticky = 0;
    $node->title= $title;
    $node->body = $body;
    $node->field_1 = $field_1;

$nid = $node->id(); // Get Nid from the node object.


Add translate Node


     * add translate Node
    $transNode = Node::load($nid);
    $transNode = $transNode->addTranslation("en");
    $transNode->title = $title_EN;
    $transNode->body= $body_EN;
    $transNode->field_1 = $field_1_EN;



Submitted by ronit (not verified) on Tue, 05/26/2020 - 13:14 Permalink

Is there any way to save multiple nodes at once in a single query Like a bulk create of multiple node objects That would be running a insert into query with an array of array of values
Add new comment

Restricted HTML

If you need some help or you search a Drupal freelancer don't hesitate to contact us.


Contact Us

All the content is FREE but I still need your help


Become a patreon