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