How can I install and update the contents of a field on a node in Drupal 7?

I wrote a Drupal 7 module that creates its own node type. I added the number_integer field in node to act as a counter. How to set default counter field to zero when node is created?

Further, when processing node, I need to increase the counter value by one and save the new value. Can I do this by changing the $ node object and then calling node_save? Or is there a better way using the fields API or something like that?

+3
source share
1 answer

I still would not dare to save node just like that. I will use anyway

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

as in Drupal 6 (only with slightly different syntax).

+1
source

Source: https://habr.com/ru/post/1789423/


All Articles