Thanks for taking the time to read my problem.
I'm trying to write a module that import content from an old version of Drupal to a new Drupal 9 website.
I managed to extract all content from the old database. It is stored in an array that I pass to a function reponsible for creating the node in the new DB. The problem I'm having is that the body of the node is not saved. Records are created in the tables node, node_field_data, node_revision, node_field_revision but nothing is created in node__body.
I tried two different methods :
1-
$node = Node::create(['type' => 'article_epingle']);
$node->langcode = $a["lang"];
$node->title = $a["title"];
// ... status, promote, ...
$node->body = array("value" => $a["body"], "format" => 'full_html');
// ... a few custom fields
$node->enforceIsNew();
$node->save();
Or
$node = Node::create(['type' => 'article_epingle']);
$node->langcode = $a["lang"];
$node->title = $a["title"];
// ... status, promote, ...
$node->body->value = $a["body"];
$node->body->format = 'full_html';
// ... a few custom fields
$node->enforceIsNew();
$node->save();
And 2 -
$node = \Drupal::entityTypeManager()
->getStorage('node')
->create(['type' => 'article_epingle',
'title' => $a["title"],
'body' => $a["body"],
// ... other fields
]);
$node->save();
The result is the same everytime, the body is not saved in DB. The save() method returns "1" and the newly created node appears in /admin/content but can't be displayed. The following error is returned if I try to display the node :
Error: Call to a member function displaySubmitted() on null in template_preprocess_node() (line 528 of core/modules/node/node.module).
Does anyone already had the same problem ?
Thanks in advance for your input !