0
votes

I have a problem with Drupal 7, I have a content type named "server", wich contains different fields :

  • hostname
  • CPU speed
  • ...

The field hostname is entered manually. The others field must be entered progamatically. So I specified a hostname and a function must search the information (CPU speed, ...) and fills the empty fields.

But I don't manage to update my node. I tried the functions hook_node_insert and hook_node_insert. When I print the node before (1) and after (2) the use of theses functions I can see the difference. But when I access the node http://localhost/drupal/?q=node/32 modifications have disappeared.

Here is a part of my function :

function module_node_presave($node) {
    if ($node->type == 'server') {

        dpm($node); //(1)
        $node->field_server_cpu_speed[LANGUAGE_NONE][0]['value']  = 55;
        dpm($node); //(2)

    }
}

Can someone help me ?

Thanks in advance, BDR

1

1 Answers

0
votes

Try the Computed field module to create the dynamic fields or add the node_save($node); at the end of the codes to save the node:

function module_node_presave($node) {
  if ($node->type == 'server') {
    $node->field_server_cpu_speed[LANGUAGE_NONE][0]['value']  = 55;
    node_save($node);
  }
}