duanaixuan7385 2017-05-05 06:52
浏览 22
已采纳

Drupal以编程方式使用body创建节点

I am trying to create nodes in Drupal 7 using a php script I then execute using Drush.

While I am able to create a basic node with a title, I am not able to set the body for some reason.

I have tried two different approaches using different advice I found on other forums.

In the first case, setting node elements directly:

...
$node->title = 'Your node title';
$node->body[$node->language][0]['value'] = "<p>this is a test</p>";
$node->body[$node->language][0]['summary'] = "body summary;
$node->body[$node->language][0]['format'] = 'full_html';

In the second cases, using Entity Wrappers:

$node_wrapper = entity_metadata_wrapper('node', $node);
$node_wrapper->body->set(array('value' => '<p>New content</p>', 'format' => 'full_html'));

In both cases I am saving the node like follows:

$node = node_submit($node);
node_save($node);

And in both cases I get a new node published, but the body never gets set or displays.

How do I correctly set the body of a new node I am saving?

  • 写回答

3条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 这种html怎么制作
      • ¥60 高仿微信的即时通讯app
      • ¥50 Window+VScode+opencv+tensorflow+anaconda实现行人检测与跟踪
      • ¥15 用AT89C51单片机汇编实现按键流水灯
      • ¥15 关于#matlab#的问题:偏微分方程降噪的程序,上面的迭代式的表达
      • ¥15 二叉树用二叉链存储问题
      • ¥15 VS2019不能设置QT的verson了,设置了点确定又消失了,怎么解决呢?
      • ¥15 用java解决,要解释一下给我
      • ¥100 项目经理想学开发牛牛指点迷津有偿
      • ¥15 vscode 配置时出现问题