Index: modules/flexinode/field_image.inc =================================================================== RCS file: /c/Docume~1/bjaspan/Home/CVSROOT/drupal-4.7/modules/flexinode/field_image.inc,v retrieving revision 1.1 diff -u -F^function -r1.1 field_image.inc --- modules/flexinode/field_image.inc 12 May 2006 00:17:17 -0000 1.1 +++ modules/flexinode/field_image.inc 2 Jun 2006 13:41:23 -0000 @@ -15,6 +15,31 @@ function flexinode_field_image_name($fie function flexinode_field_image_form($field, $node) { $fieldname = 'flexinode_'. $field->field_id; + // Most field elements (e.g. text fields) can have a pre-existing + // value loaded into them for display to the user, but a file upload + // input cannot. Therefore, if a previous value for this field + // exists, we add a pointer to it to the form as a hidden element + // with a _old name suffix. When flexinode_submit uses our _execute + // function to obtain the file object for the field, it uses the new + // value if available or the old one if not. + // + // As a consequence of this approach, even if this field is + // "required" by flexinode, it cannot be marked #required => TRUE in + // the form because it is not in fact required in the Forms API + // sense; it is not an error for it to be absent in a submission if + // a corresponding _old value is available. Therefore, always mark + // it as not required. If the field is required by flexinode, our + // _validate function, called by flexinode_validate, will verify + // that it has a new or old value. + // + // Not marking the form field as #required => TRUE means that it + // will not be themed as a required field even though (from the UI + // perspective) it is. This could be solved by teaching the Forms + // API a new attribute, #display_required, which if TRUE means to + // theme the element as required even if #required is FALSE; i.e. it + // would be for any element whose required-ness is enforced by a + // custom validate function. + if ($node->$fieldname) { $form[$fieldname .'_old'] = array( '#type' => 'hidden', @@ -25,7 +50,7 @@ function flexinode_field_image_form($fie '#type' => 'file', '#title' => t($field->label), '#description' => ($node->$fieldname ? t('"%filename" has been uploaded. If you upload another file, the current file will be replaced.', array('%filename' => $node->$fieldname->filename)) : '') .' '. t($field->description) .' '. t('The file is limited to %kbKB and a resolution of %wxh pixels (width x height).', array('%wxh' => $field->options[1], '%kb' => $field->options[4])), - '#required' => $field->required, + '#required' => FALSE, // *not* $field->required, see above '#weight' => $field->weight, ); @@ -98,6 +123,13 @@ function flexinode_field_image_validate( } elseif(!empty($node->$fieldname)) { form_set_error($fieldname, t('The image upload was not successful.')); + } + // see comment in flexinode_field_image_form + elseif ($field->required && empty($node->$fieldname) && + empty($node->{$fieldname.'_old'})) { + form_set_error($fieldname, t('%label is required', + array('%label' => + theme('placeholder', $field->label)))); } }