0

here is my code:

$nid = $entity->field_empf_number['und']['0']['nid'];  
$result = db_query("SELECT MAX(entity_id) FROM field_data_field_empf_number WHERE field_empf_number_nid = $nid")->fetchField();  
if (isset($result)){  
  $n = $result ;  
  $node = node_load($n);  
  $node->field_empf_stat['und']['0']['value'] = 'off';  //list field  
  node_save($node);  
}  
$entity_field[0]['value'] = $result;`

when add new node (if there is previous node i mean the if statement return true ) this error message show up:

Fatal error: Maximum function nesting level of '100' reached, aborting! in C:\wamp\www\finance\includes\database\database.inc on line 429

I googled but i did not found any answers.

6
  • 2
    I guess you are calling this in one of the node hooks which will become infinite loop because of node_save in the code !!
    – Anil Sagar
    Commented Oct 16, 2012 at 11:50
  • are you telling me to write "node_Save" function out of the if statement? Commented Oct 16, 2012 at 12:27
  • I mean where is above code written ??
    – Anil Sagar
    Commented Oct 16, 2012 at 12:30
  • 2
    What Anil means is that the computed field is probably computed when a node is saved. Since you save a node (again) the computed field is computed again, which causes a node to be saved, which causes the computed field to be saved, and so on, forever.
    – Letharion
    Commented Oct 16, 2012 at 13:15
  • but this problem caused when creating new node Commented Oct 16, 2012 at 14:17

2 Answers 2

1

Try to change the node_save($node) to drupal_register_shutdown_function('node_save', $node). It will remove the old node saving process from the actual node saving. But I don't think, that type of code should have place within a computed field. The computed field good to modify the same field. It isn't designed for modifying other data of your system. These code should be in a custom module in hook_node_presave().

0

The code for the computed field should preferrably be placed in your module, not in your database. This will make your code much easier to debug so the abovementioned errors won't happen.

Use the computed field hook - here is a nice (tutorial).

Here are some code examples.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.