/** * This function wraps the form manager processing. If processing is successful, (that is, * only 'save'). If editing was successful, the form is frozen in case you want * to display it again (usually you want to redirect to the view target). * * There are several possible return values: * * - <i>save</i> and the variants <i>next</i> and <i>previous</i> (for wizard usage) suggest * successful form processing. The form has already been validated, synchronized with and * saved to the data source. * - <i>cancel</i> the user cancelled the form processing, no I/O has been done. * - <i>edit</i>, <i>previous</i>, <i>next</i> indicates that the form is not yet successfully * completed. This can mean many things, including validation errors, which the renderer * already outlines in the Form output. No I/O processing has been done. * * The form will be automatically validated for 'save' and 'next', but not for 'previous'. * If you want to have save the data for example even during 'next', you need to call * datamanager->save after this function returned the according return code. * * Normally, all validation should be done during the Form processing, but sometimes this is * not possible. These are the cases where type validation rules fail instead of form validation * ones. At this time, the integration of type validation is rudimentary and will * transparently return edit instead of validation. * * @return string One of 'save', 'cancel', 'next', 'previous', 'edit', depending on the schema * configuration. * @todo Integrate type validation checks cleanly. */ function process_form() { if ($this->formmanager === null) { throw new midcom_error('You must initialize a controller class before using it.'); } $result = $this->formmanager->process_form(); // Remove the lock if ($this->lock_timeout && ($result === 'save' || $result === 'cancel')) { midcom_helper_datamanager2_controller::set_lock($this->datamanager->storage->object, 0); } elseif (!midcom_helper_datamanager2_controller::is_locked($this->datamanager->storage->object, $this->lock_timeout)) { midcom_helper_datamanager2_controller::set_lock($this->datamanager->storage->object, $this->lock_timeout); } // Handle successful save explicitly. if ($result == 'save' || $result == 'next') { // Ok, we can save now. At this point we already have a content object. if (!$this->datamanager->validate()) { // In case that the type validation fails, we bail with an exception, until // we have a better defined way-of-life here. throw new midcom_error("Failed to save object, type validation failed:\n" . implode("\n", $this->datamanager->validation_errors)); } if ($result == 'save') { if (!$this->datamanager->save()) { if (count($this->datamanager->validation_errors) > 0) { debug_add('Type validation failed. Reverting to edit mode transparently.'); debug_print_r('Validation error listing:', $this->datamanager->validation_errors); $result = 'edit'; } else { // It seems to be a critical error. throw new midcom_error('Failed to save the data to disk, last midgard error code: ' . midcom_connection::get_error_string() . '. Check the debug level log for more information.'); } } } } // all others stay untouched. return $result; }