In the description under "Computed Code" I understand that I can put the code in a file and then call the appropriate function. However, I do not succeed to do so.

I have put the code outside in a file (in my theme) following the description: "Alternately, this code can be supplied by your own custom function named computed_field_field_event_hebrew_date_compute()."

When trying to use the field, i.e., when editing a node of a type which has the computed field I get a fatal error: Cannot redeclare computed_field_field_event_hebrew_date_compute() (previously declared in /home/amir/domains/kehilotsharot.org.il/public_html/sites/all/themes/tendu/custom_functions.php:5) in /home/amir/domains/kehilotsharot.org.il/public_html/sites/all/themes/tendu/custom_functions.php on line 17

which means that the method in the file is indeed recognized but it seems that computed field tries to re-declare it.

If I go to edit the computed field itself, I see that the default code has been entered to it:
$node_field[0]['value'] = "";

Any help will be appreciated. Thanks!

Comments

quickcel’s picture

You can put the code in a separate module and then call the appropriate function from there.

For example, if you create a new custom module you can put all of your needed Computed Code functions in the .module file and the Computed Field module will automatically detect that the custom function is present and use it.

Here is an example of the function that I have in my custom .module file:

<?php
function computed_field_field_calc_interest_amount_compute(&$node, $field, &$node_field) {
  $principal = $node->field_calc_principal[0]['value'];
  $interest_rate = $node->field_calc_interest_rate[0]['value'] / 100;
  $time_months = $node->field_calc_time_months[0]['value'] / 12;
  $node_field[0]['value'] = $principal * $interest_rate * $time_months;
  return $node_field[0]['value'];
}
?>

You would obviously need to change the name of the function to whatever suits your needs.

mmjvb’s picture

Issue summary: View changes
Status: Active » Closed (outdated)