ENH: saveInto() new extension points. (#10636)

* ENH: saveInto() new extension points.
This commit is contained in:
Mojmir Fendek 2023-01-13 09:43:22 +13:00 committed by GitHub
parent 0d662ba95f
commit 2c105cffc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
} }
/** /**