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)
|
public function saveInto(DataObjectInterface $dataObject, $fieldList = null)
|
||||||
{
|
{
|
||||||
|
$form = $this;
|
||||||
|
$dataObject->invokeWithExtensions('onBeforeFormSaveInto', $form, $fieldList);
|
||||||
|
|
||||||
$dataFields = $this->fields->saveableFields();
|
$dataFields = $this->fields->saveableFields();
|
||||||
$lastField = null;
|
$lastField = null;
|
||||||
|
|
||||||
if ($dataFields) {
|
if ($dataFields) {
|
||||||
foreach ($dataFields as $field) {
|
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 ?? [])) {
|
if ($fieldList && is_array($fieldList) && !in_array($field->getName(), $fieldList ?? [])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$saveMethod = "save{$field->getName()}";
|
$saveMethod = "save{$field->getName()}";
|
||||||
|
|
||||||
if ($field->getName() == "ClassName") {
|
if ($field->getName() == "ClassName") {
|
||||||
$lastField = $field;
|
$lastField = $field;
|
||||||
} elseif ($dataObject->hasMethod($saveMethod)) {
|
} elseif ($dataObject->hasMethod($saveMethod)) {
|
||||||
@ -1506,9 +1511,12 @@ class Form extends ViewableData implements HasRequestHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($lastField) {
|
if ($lastField) {
|
||||||
$lastField->saveInto($dataObject);
|
$lastField->saveInto($dataObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$dataObject->invokeWithExtensions('onAfterFormSaveInto', $form, $fieldList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user