/**
  * Save the contents of this form into the given data object.
  * It will make use of setCastedField() to do this.
  *
  * @param DataObjectInterface $dataObject The object to save data into
  * @param FieldList $fieldList An optional list of fields to process.  This can be useful when you have a
  * form that has some fields that save to one object, and some that save to another.
  */
 public function saveInto(DataObjectInterface $dataObject, $fieldList = null)
 {
     $dataFields = $this->fields->saveableFields();
     $lastField = null;
     if ($dataFields) {
         foreach ($dataFields as $field) {
             // 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;
             } else {
                 if ($dataObject->hasMethod($saveMethod)) {
                     $dataObject->{$saveMethod}($field->dataValue());
                 } else {
                     if ($field->getName() != "ID") {
                         $field->saveInto($dataObject);
                     }
                 }
             }
         }
     }
     if ($lastField) {
         $lastField->saveInto($dataObject);
     }
 }
 /**
  * Save the results into the form
  * Calls function $record->onChange($items) before saving to the assummed
  * Component set.
  *
  * @param DataObjectInterface $record
  */
 public function saveInto(DataObjectInterface $record)
 {
     // Detect whether this field has actually been updated
     if ($this->value !== 'unchanged') {
         $items = array();
         $fieldName = $this->name;
         $saveDest = $record->{$fieldName}();
         if (!$saveDest) {
             user_error("TreeMultiselectField::saveInto() Field '{$fieldName}' not found on" . " {$record->class}.{$record->ID}", E_USER_ERROR);
         }
         if ($this->value) {
             $items = preg_split("/ *, */", trim($this->value));
         }
         // Allows you to modify the items on your object before save
         $funcName = "onChange{$fieldName}";
         if ($record->hasMethod($funcName)) {
             $result = $record->{$funcName}($items);
             if (!$result) {
                 return;
             }
         }
         $saveDest->setByIDList($items);
     }
 }
 /**
  * Save the current value of this MultiSelectField into a DataObject.
  * If the field it is saving to is a has_many or many_many relationship,
  * it is saved by setByIDList(), otherwise it creates a comma separated
  * list for a standard DB text/varchar field.
  *
  * @param DataObject|DataObjectInterface $record The record to save into
  */
 public function saveInto(DataObjectInterface $record)
 {
     $fieldName = $this->getName();
     if (empty($fieldName) || empty($record)) {
         return;
     }
     $relation = $record->hasMethod($fieldName) ? $record->{$fieldName}() : null;
     // Detect DB relation or field
     $items = $this->getValueArray();
     if ($relation instanceof Relation) {
         // Save ids into relation
         $relation->setByIDList($items);
     } elseif ($record->hasField($fieldName)) {
         // Save dataValue into field
         $record->{$fieldName} = $this->stringEncode($items);
     }
 }
 /**
  * @param DataObject|DataObjectInterface $record
  * @return $this
  */
 public function saveInto(DataObjectInterface $record)
 {
     // Check required relation details are available
     $fieldname = $this->getName();
     if (!$fieldname) {
         return $this;
     }
     // Get details to save
     $idList = $this->getItemIDs();
     // Check type of relation
     $relation = $record->hasMethod($fieldname) ? $record->{$fieldname}() : null;
     if ($relation && ($relation instanceof RelationList || $relation instanceof UnsavedRelationList)) {
         // has_many or many_many
         $relation->setByIDList($idList);
     } elseif (DataObject::getSchema()->hasOneComponent(get_class($record), $fieldname)) {
         // has_one
         $record->{"{$fieldname}ID"} = $idList ? reset($idList) : 0;
     }
     return $this;
 }
 /**
  * 30/06/2009 - Enhancement:
  * SaveInto checks if set-methods are available and use them
  * instead of setting the values in the money class directly. saveInto
  * initiates a new Money class object to pass through the values to the setter
  * method.
  *
  * (see @link MoneyFieldTest_CustomSetter_Object for more information)
  *
  * @param DataObjectInterface|Object $dataObject
  */
 public function saveInto(DataObjectInterface $dataObject)
 {
     $fieldName = $this->getName();
     if ($dataObject->hasMethod("set{$fieldName}")) {
         $dataObject->{$fieldName} = DBField::create_field('Money', array("Currency" => $this->fieldCurrency->dataValue(), "Amount" => $this->fieldAmount->dataValue()));
     } else {
         $currencyField = "{$fieldName}Currency";
         $amountField = "{$fieldName}Amount";
         $dataObject->{$currencyField} = $this->fieldCurrency->dataValue();
         $dataObject->{$amountField} = $this->fieldAmount->dataValue();
     }
 }