Skip to content

Commit

Permalink
ENH: New extension points added (JSON field).
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendeksilverstripe committed Jun 20, 2023
1 parent 8533d27 commit 6b69001
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Form/JsonField.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,19 @@ public function saveInto(DataObjectInterface $record)
if ($jsonDataObjectID && $jsonDataObject = $record->$fieldname) {
if ($value) {
$jsonDataObject = $jsonDataObject->setData($value);
$this->extend('onBeforeLinkEdit', $jsonDataObject, $record);
$jsonDataObject->write();
$this->extend('onAfterLinkEdit', $jsonDataObject, $record);
} else {
$this->extend('onBeforeLinkDelete', $jsonDataObject, $record);
$jsonDataObject->delete();
$record->{"{$fieldname}ID"} = 0;
$this->extend('onAfterLinkDelete', $jsonDataObject, $record);
}
} elseif ($value) {
$jsonDataObject = new $class();
$jsonDataObject = $jsonDataObject->setData($value);
$this->extend('onBeforeLinkCreate', $jsonDataObject, $record);
$jsonDataObject->write();
$record->{"{$fieldname}ID"} = $jsonDataObject->ID;
$this->extend('onAfterLinkCreate', $jsonDataObject, $record);
Expand Down

0 comments on commit 6b69001

Please sign in to comment.