drupal9:在sql中作为节点保存形式(自定义模块示例)
我开发了一个具有表单的自定义模块,以将数据保存在SQL-datebase中。我想用于节点结构。
正常的SQL保存示例表可工作,但对于节点表不适。 知道怎么了?
这是我的保存代码,它可以在非节点表中工作:
public function submitForm(array &$form, FormStateInterface $form_state) { $connection = \Drupal::service('database');
$result = $connection->insert('node.node__body')
->fields(['body_value'])
->values([
'body_value' => 'text for body',
])
->execute();
$form_state->setRedirect('modulname.form');
}
i develop a custom module with forms to save data in SQL-Datebase. I want to use for that the node-structure.
Normal SQL-savings for example table works but not for the node-tables.
Any idea what is going wrong?
This ist my Code for saving, which works in non-node-tables:
public function submitForm(array &$form, FormStateInterface $form_state) { $connection = \Drupal::service('database');
$result = $connection->insert('node.node__body')
->fields(['body_value'])
->values([
'body_value' => 'text for body',
])
->execute();
$form_state->setRedirect('modulname.form');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用Drupal中的实体API来操纵或创建节点。
在您的情况下
,
类型
是内容类型的机器名称。不要忘记自己更新。另外,您可能要注入entity_type.manager服务并在代码中使用。在此处获取更多信息:与实体合作在Drupal 中
Use Entity API in Drupal to manipulate or create a node.
In your case,
Here,
type
is the content type machine name. Don't forget to update with your own. Also you probably want to inject the entity_type.manager service and use in the code.Get more info here: Working with entities in Drupal