*** computed_field.module.orig 2009-08-01 01:38:42.000000000 +0200 --- computed_field.module 2010-04-19 13:00:04.296222154 +0200 *************** *** 26,31 **** --- 26,32 ---- $form = array(); $compute_func = 'computed_field_'. $field['field_name'] .'_compute'; $display_func = 'computed_field_'. $field['field_name'] .'_display'; + $validate_func = 'computed_field_'. $field['field_name'] .'_validate'; // these next 3 have been moved from widget to field, so they copy default values from widget $form['code'] = array( '#type' => 'textarea', *************** *** 54,59 **** --- 55,74 ---- '#value' => t('This field is computed using @display_func().', array('@display_func' => $display_func)), ); } + $form['validate'] = array( + '#type' => 'textarea', + '#rows' => 15, + '#title' => t('Code for validation'), + '#description' => t('The variables available to your code are: ') .'&$node, $field, and &$node_field'. t('Alternately, this code can be supplied by your own custom function named @validate_func().', array('@validate_func' => $validate_func)), + '#default_value' => !empty($field['validate']) ? $field['validate'] : '', + '#access' => !function_exists($validate_func), + ); + if (function_exists($validate_func)) { + $form['validate_func'] = array( + '#type' => 'item', + '#value' => t('This field is computed using @validate_func().', array('@validate_func' => $validate_func)), + ); + } $form['store'] = array( '#type' => 'checkbox', '#title' => t('Store using the database settings below'), *************** *** 102,108 **** } break; case 'save': ! return array('code', 'display_format', 'store', 'data_type', 'data_length', 'data_not_NULL', 'data_default', 'data_sortable'); case 'database columns': if ($field['store']) { $columns = array('value' => array()); --- 117,123 ---- } break; case 'save': ! return array('code', 'display_format', 'validate', 'store', 'data_type', 'data_length', 'data_not_NULL', 'data_default', 'data_sortable'); case 'database columns': if ($field['store']) { $columns = array('value' => array()); *************** *** 189,194 **** --- 204,217 ---- return theme('field', $node, $field, $items, $teaser, $page); break; case 'validate': + $validate_func = 'computed_field_'. $field['field_name'] .'_validate'; + if (function_exists($validate_func)) { + $validate_func($node, $field, $node_field); + } else { + if (isset($field['validate'])) { + eval($field['validate']); + } + } break; case 'insert': case 'update':