mirror of
https://github.com/silverstripe/silverstripe-multiform
synced 2024-10-22 11:05:49 +02:00
ENHANCEMENT Added MultiFormStep->saveInto() to simulate Form->saveInto() behaviour with a stub form. This is preferred method of saving step data into a DataObject, instead of using $myObj->update($myStep->loadData()), is update() doesn't trigger custom formfield saving behaviour (e.g. to save relations on an existing dataobject for CheckboxSetField)
This commit is contained in:
parent
a8877b780f
commit
a867db5fe8
@ -158,6 +158,29 @@ class MultiFormStep extends DataObject {
|
||||
$this->write();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the data on this step into an object,
|
||||
* similiar to {@link Form->saveInto()} - by building
|
||||
* a stub form from {@link getFields()}. This is necessary
|
||||
* to trigger each {@link FormField->saveInto()} method
|
||||
* individually, rather than assuming that all data
|
||||
* serialized through {@link saveData()} can be saved
|
||||
* as a simple value outside of the original FormField context.
|
||||
*
|
||||
* @param DataObject $obj
|
||||
*/
|
||||
public function saveInto($obj) {
|
||||
$form = new Form(
|
||||
new Controller(),
|
||||
'Form',
|
||||
$this->getFields(),
|
||||
new FieldSet()
|
||||
);
|
||||
$form->loadDataFrom($this->loadData());
|
||||
$form->saveInto($obj);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation for a step. In most cases, it should be sufficient
|
||||
* to have built-in validation through the {@link Validator} class
|
||||
@ -271,6 +294,13 @@ class MultiFormStep extends DataObject {
|
||||
$this->form = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Form
|
||||
*/
|
||||
public function getForm() {
|
||||
return $this->form;
|
||||
}
|
||||
|
||||
// ##################### Utility ####################
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user