Saturday, May 25, 2019

Create node programatically with translation content in Drupal 8

            $node = Node::create(array(
                'type' => 'news',
                'langcode' => 'en',
                'uid' => '1',
                'status' => 1,
                'title' => $node['Title'],
                'field_description' =>array(0=>array('value'=>$node['PublishingPageContent'],'summary'=>$node['Comments'],'format'=>'full_html')),
                'field_news_type' =>121
         ));

             $node->save();
             $node_fr = $node->addTranslation('fr');
             $node_fr->title = 'frenchtitle';
             $node_fr->body->summary = 'summary';
             $node_fr->body->value = 'frenchcontent';
             $node_fr->body->format = 'full_html';

            //Saving the node
             $node_fr->save();   

No comments:

Post a Comment