? .DS_Store
Index: computed_field.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/computed_field/computed_field.module,v
retrieving revision 1.17.2.6
diff -u -p -r1.17.2.6 computed_field.module
--- computed_field.module	19 May 2009 00:44:17 -0000	1.17.2.6
+++ computed_field.module	31 Jul 2009 23:10:25 -0000
@@ -24,14 +24,23 @@ function computed_field_field_settings($
   switch ($op) {
     case 'form':
       $form = array();
+      $compute_func = 'computed_field_'. $field['field_name'] .'_compute';
+      $display_func = 'computed_field_'. $field['field_name'] .'_display';
       // these next 3 have been moved from widget to field, so they copy default values from widget
       $form['code'] = array(
         '#type' => 'textarea',
         '#rows' => 15,
         '#title' => t('Computed Code'),
-        '#description' => t('The variables available to your code are: ') .'<code>&amp;$node, $field, and &amp;$node_field</code>'. t('. To set the value of the field, set ') .'<code>$node_field[0][\'value\']</code>'. t('. Here\'s a simple example which sets the computed field\'s value to the value of the sum of the number fields field_a and field_b: ') .'<code>$node_field[0][\'value\'] = $node->field_a[0][\'value\'] + $node->field_b[0][\'value\'];</code>',
+        '#description' => t('The variables available to your code are: ') .'<code>&amp;$node, $field, and &amp;$node_field</code>'. t('. To set the value of the field, set ') .'<code>$node_field[0][\'value\']</code>'. t('. Here\'s a simple example which sets the computed field\'s value to the value of the sum of the number fields field_a and field_b: ') .'<code>$node_field[0][\'value\'] = $node->field_a[0][\'value\'] + $node->field_b[0][\'value\'];</code>. '. t('Alternately, this code can be supplied by your own custom function named @compute_func().', array('@compute_func' => $compute_func)),
         '#default_value' => !empty($field['code']) ? $field['code'] : '$node_field[0][\'value\'] = "";',
+        '#access' => !function_exists($compute_func),
       );
+      if (function_exists($compute_func)) {
+        $form['compute_func'] = array(
+          '#type' => 'item',
+          '#value' => t('This field is computed using @compute_func().', array('@compute_func' => $compute_func)),
+          );
+      }
       $form['display'] = array(
         '#type' => 'checkbox',
         '#title' => t('Display this field'),
@@ -40,9 +49,16 @@ function computed_field_field_settings($
       $form['display_format'] = array(
         '#type' => 'textarea',
         '#title' => t('Display Format'),
-        '#description' => t('This code should assign a string to the $display variable, which will be printed as the value of the field. The stored value of the field is in $node_field_item[\'value\'].  Note: this code has no effect if you use the "Computed Value" formatter option.'),
+        '#description' => t('This code should assign a string to the $display variable, which will be printed as the value of the field. The stored value of the field is in $node_field_item[\'value\'].  Note: this code has no effect if you use the "Computed Value" formatter option. Alternately, this code can be supplied by your own custom function named @display_func().', array('@display_func' => $display_func)) ,
         '#default_value' => !empty($field['display_format']) ? $field['display_format'] : '$display = $node_field_item[\'value\'];',
+        '#access' => !function_exists($display_func),
       );
+      if (function_exists($display_func)) {
+        $form['display_func'] = array(
+          '#type' => 'item',
+          '#value' => t('This field is computed using @display_func().', array('@display_func' => $display_func)),
+          );
+      }
       $form['store'] = array(
         '#type' => 'checkbox',
         '#title' => t('Store using the database settings below'),
@@ -140,8 +156,15 @@ function computed_field_field_settings($
 }
 
 function _computed_field_compute_value(&$node, $field, &$node_field) {
-  if (isset($field['code'])) {
-    eval($field['code']);
+  // Allow the value to be computed from code not stored in DB
+  $compute_func = 'computed_field_'. $field['field_name'] .'_compute';
+  if (function_exists($compute_func)) {
+    $compute_func($node, $field, $node_field);
+  }
+  else {
+    if (isset($field['code'])) {
+      eval($field['code']);
+    }
   }
 }
 
@@ -272,7 +295,15 @@ function theme_computed_field_formatter_
   $field = content_fields($element['#field_name']);
   // For "some" backwards compatibility
   $node_field_item['value'] = $element['#item']['value'];
-  eval($field['display_format']);
+
+  // Allow the value to be formated from code not stored in DB
+  $display_func = 'computed_field_'. $field['field_name'] .'_display';
+  if (function_exists($display_func)) {
+    $display = $display_func($field, $element);
+  }
+  else {
+    eval($field['display_format']);
+  }
   return $display;
 }
 
@@ -283,7 +314,15 @@ function theme_computed_field_formatter_
   $field = content_fields($element['#field_name']);
   // For "some" backwards compatibility
   $node_field_item['value'] = $element['#item']['value'];
-  eval($field['display_format']);
+
+  // Allow the value to be formated from code not stored in DB
+  $display_func = 'computed_field_'. $field['field_name'] .'_display';
+  if (function_exists($display_func)) {
+    $display = $display_func($field, $element);
+  }
+  else {
+    eval($field['display_format']);
+  }
   return check_plain($display);
 }
 
@@ -294,7 +333,15 @@ function theme_computed_field_formatter_
   $field = content_fields($element['#field_name']);
   // For "some" backwards compatibility
   $node_field_item['value'] = $element['#item']['value'];
-  eval($field['display_format']);
+
+  // Allow the value to be formated from code not stored in DB
+  $display_func = 'computed_field_'. $field['field_name'] .'_display';
+  if (function_exists($display_func)) {
+    $display = $display_func($field, $element);
+  }
+  else {
+    eval($field['display_format']);
+  }
   return check_markup($display);
 }
 
