Drupal 9 - 为什么我的 body 没有用 Node::create() 保存

Drupal 9 - Why is my body not saved with Node::create()

感谢您花时间阅读我的问题。

我正在尝试编写一个模块,将内容从旧版本的 Drupal 导入到新的 Drupal 9 网站。

我设法从旧数据库中提取了所有内容。它存储在我传递给负责在新数据库中创建节点的函数的数组中。我遇到的问题是节点的 body 没有保存。记录在表节点 node_field_data、node_revision、node_field_revision 中创建,但在 node__body.

中未创建任何内容

我尝试了两种不同的方法:

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();

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

和 2 -

$node = \Drupal::entityTypeManager()
                 ->getStorage('node')
                 ->create(['type' => 'article_epingle',
                           'title' => $a["title"],
                           'body' => $a["body"],
                           // ... other fields
                           ]);
$node->save();

结果每次都一样,body没有保存在数据库中。 save()方法returns“1”,新建的节点出现在/admin/content但无法显示。如果我尝试显示节点,则会返回以下错误:

错误:在 template_preprocess_node() 中调用成员函数 displaySubmitted() 为空(core/modules/node/node.module 的第 528 行)。

有人遇到过同样的问题吗?

提前感谢您的意见!

我解决了我的问题。

我想我在安装 Drupal 时做错了什么,因为我的代码在重新安装所有内容后工作正常。