Пример #1
0
 /**
  * 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);
     }
 }