mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENH: saveInto() new extension points. (#10636)
* ENH: saveInto() new extension points.
This commit is contained in:
parent
0d662ba95f
commit
2c105cffc9
@ -1487,16 +1487,21 @@ class Form extends ViewableData implements HasRequestHandler
|
||||
*/
|
||||
public function saveInto(DataObjectInterface $dataObject, $fieldList = null)
|
||||
{
|
||||
$form = $this;
|
||||
$dataObject->invokeWithExtensions('onBeforeFormSaveInto', $form, $fieldList);
|
||||
|
||||
$dataFields = $this->fields->saveableFields();
|
||||
$lastField = null;
|
||||
|
||||
if ($dataFields) {
|
||||
foreach ($dataFields as $field) {
|
||||
// Skip fields that have been excluded
|
||||
// Skip fields that have been excluded
|
||||
if ($fieldList && is_array($fieldList) && !in_array($field->getName(), $fieldList ?? [])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$saveMethod = "save{$field->getName()}";
|
||||
|
||||
if ($field->getName() == "ClassName") {
|
||||
$lastField = $field;
|
||||
} elseif ($dataObject->hasMethod($saveMethod)) {
|
||||
@ -1506,9 +1511,12 @@ class Form extends ViewableData implements HasRequestHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($lastField) {
|
||||
$lastField->saveInto($dataObject);
|
||||
}
|
||||
|
||||
$dataObject->invokeWithExtensions('onAfterFormSaveInto', $form, $fieldList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user