2017-05-05 06:52
浏览 22


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

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?

图片转代码服务由CSDN问答提供 功能建议

我正在尝试使用php脚本在Drupal 7中创建节点然后使用Drush执行。 \ n


我尝试了两种不同的方法使用不同的 我在其他论坛上找到的建议。


 $ node-  &gt; title ='您的节点标题'; 
 $ node-&gt; body [$ node-&gt; language] [0] ['value'] =“&lt; p&gt;这是一个测试&lt; / p&gt;”;  
 $ node-&gt; body [$ node-&gt; language] [0] ['summary'] =“body summary; 
 $ node-&gt; body [$ node-&gt; language] [0] ['  format'] ='full_html'; 

在第二种情况下,使用Entity Wrappers:

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

在这两种情况下,我都像fo一样保存节点 llows:

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


如何正确设置我正在保存的新节点的主体? \ n

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题