I'm trying to import some nodes into a new D8 installation. Therefore I wrote a module. Importing nodes is already working perfectly. As you can see in my code snippet, I'm using the $field_array variable to create the nodes. Now my questione: is it possible to use this variable also for the node update functionality?
Regards
M.
public function ausgabe($import_node,$action,$new_old_uid,$new_old_nid) {
global $content_type;
$lang = $this->get_current_language();
$field_array = [
'uid' => $new_old_uid["new_uid"],
'type' => $content_type,
'langcode' => $lang,
'status' => $import_node->status,
'created' => $import_node->created ,
'changed' => $import_node->changed ,
'title' => $import_node->title,
'body' => [
'summary' => "",
'value' => (isset($import_node->body) && !empty($import_node->body)) ? $import_node->body : "",
'format' => 'full_html',
],
'field_teaser' => [
'value' => (isset($import_node->teaser) && !empty($import_node->teaser)) ? $import_node->teaser : "",
'format' => 'full_html',
],
'field_onid' => array('value'=>$import_node->nid),
'field_image' => $this->get_set_images($import_node->field_ausgabe_bild),
'field_files' => $this->get_set_files($import_node->files),
];
if($action == "create") {
$node = Node::create($field_array);
} else {
$node = Node::load($new_old_nid["new_nid"]);
}
$node->save();
\Drupal::service('path.alias_storage')->save("/node/" . $node->id(), '/'.$import_node->path, $lang);
echo $action.": Node " . $import_node->title . ' ('.$node->id().') <br>';
$this->pre("",true);
}