public function saveInto(DataObjectInterface $record) { if ($this->record) { // HACK: Use a fake Form object to save data into fields $form = new Form($this->record, $this->name . '-form', $this->FieldList(false), new FieldList()); $form->loadDataFrom($this->value); $form->saveInto($this->record); // Save extra data into field if (count($this->extraData)) { $this->record->castedUpdate($this->extraData); } if (!$this->record->ID && count($this->defaultFromParent)) { foreach ($this->defaultFromParent as $pField => $rField) { if (is_numeric($pField)) { if ($this->record->{$rField}) { continue; } $this->record->setCastedField($rField, $record->{$rField}); } else { if ($this->record->{$pField}) { continue; } $this->record->setCastedField($rField, $record->{$pField}); } } } if (count($this->overrideFromParent)) { foreach ($this->overrideFromParent as $pField => $rField) { if (is_numeric($pField)) { $this->record->setCastedField($rField, $record->{$rField}); } else { $this->record->setCastedField($rField, $record->{$pField}); } } } $this->record->write(); $fieldName = substr($this->name, -2) == 'ID' ? $this->name : $this->name . 'ID'; $record->{$fieldName} = $this->record->ID; unset($form); } }