开发者

What is the proper way to set and update the contents of a field on a node in Drupal 7?

开发者 https://www.devze.com 2023-02-08 05:26 出处:网络
I\'ve written a Drupal 7 module that creates a custom node type. I\'ve added a number_integer field to the node, to act as a counter. How do I set the counter field to default to zero, when a node get

I've written a Drupal 7 module that creates a custom node type. I've added a number_integer field to the node, to act as a counter. How do I set the counter field to default to zero, when a node gets created?

Next, while processing the node, I ne开发者_如何学编程ed to increase the value of the counter by one and save the new value. Do I do that by altering the $node object and then calling node_save? Or is there a better way, using the Field API or something?


I still would not really dare to save back a node just like that. I would still use

  $form_state = array('values' => array());
  drupal_form_submit('story_node_form', $form_state, $node);

much like we did in Drupal 6 (just with slightly different syntax).

0

精彩评论

暂无评论...
验证码 换一张
取 消