/**
  * Method to save this form field into the given {@link DataObject}.
  *
  * By default, makes use of $this->dataValue()
  *
  * @param DataObject|DataObjectInterface $record DataObject to save data into
  */
 public function saveInto(DataObjectInterface $record)
 {
     if ($this->name) {
         $record->setCastedField($this->name, $this->dataValue());
     }
 }
Exemplo n.º 2
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);
     }
 }
 public function saveInto(DataObjectInterface $record)
 {
     if ($record->hasField($this->name) && $record->escapeTypeForField($this->name) != 'xml') {
         throw new Exception('HTMLEditorField->saveInto(): This field should save into a HTMLText or HTMLVarchar field.');
     }
     // Sanitise if requested
     $htmlValue = Injector::inst()->create('HTMLValue', $this->Value());
     if ($this->config()->sanitise_server_side) {
         $santiser = Injector::inst()->create('HTMLEditorSanitiser', HTMLEditorConfig::get_active());
         $santiser->sanitise($htmlValue);
     }
     // optionally manipulate the HTML after a TinyMCE edit and prior to a save
     $this->extend('processHTML', $htmlValue);
     // Store into record
     $record->{$this->name} = $htmlValue->getContent();
 }
 public function saveInto(DataObjectInterface $record)
 {
     $completeNumber = static::joinPhoneNumber($this->parseValue());
     $record->setCastedField($this->getName(), $completeNumber);
 }
 /**
  * @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;
 }
 /**
  * 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);
     }
 }
 public function saveInto(DataObjectInterface $record)
 {
     // Check required relation details are available
     $name = $this->getName();
     if (!$name) {
         return $this;
     }
     $value = $this->Value();
     foreach (array('Filename', 'Hash', 'Variant') as $part) {
         $partValue = isset($value[$part]) ? $value[$part] : null;
         $record->setField("{$name}{$part}", $partValue);
     }
     return $this;
 }
 /**
  * Update the permission set associated with $record DataObject
  *
  * @param DataObjectInterface $record
  */
 public function saveInto(DataObjectInterface $record)
 {
     $fieldname = $this->name;
     $managedClass = $this->managedClass;
     // Remove all "privileged" permissions if the currently logged-in user is not an admin
     $privilegedPermissions = Permission::config()->privileged_permissions;
     if (!Permission::check('ADMIN')) {
         foreach ($this->value as $id => $bool) {
             if (in_array($id, $privilegedPermissions)) {
                 unset($this->value[$id]);
             }
         }
     }
     // remove all permissions and re-add them afterwards
     $permissions = $record->{$fieldname}();
     foreach ($permissions as $permission) {
         $permission->delete();
     }
     if ($fieldname && $record && ($record->hasManyComponent($fieldname) || $record->manyManyComponent($fieldname))) {
         if (!$record->ID) {
             $record->write();
         }
         // We need a record ID to write permissions
         $idList = array();
         if ($this->value) {
             foreach ($this->value as $id => $bool) {
                 if ($bool) {
                     $perm = new $managedClass();
                     $perm->{$this->filterField} = $record->ID;
                     $perm->Code = $id;
                     $perm->write();
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
 /**
  * 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();
     }
 }
Exemplo n.º 11
0
 public function saveInto(DataObjectInterface $record)
 {
     if (!isset($_FILES[$this->name])) {
         return false;
     }
     $fileClass = File::get_class_for_file_extension(File::get_file_extension($_FILES[$this->name]['name'], PATHINFO_EXTENSION));
     if ($this->relationAutoSetting) {
         // assume that the file is connected via a has-one
         $objectClass = $record->hasOne($this->name);
         if ($objectClass === 'File' || empty($objectClass)) {
             // Create object of the appropriate file class
             $file = Object::create($fileClass);
         } else {
             // try to create a file matching the relation
             $file = Object::create($objectClass);
         }
     } else {
         if ($record instanceof File) {
             $file = $record;
         } else {
             $file = Object::create($fileClass);
         }
     }
     $this->upload->loadIntoFile($_FILES[$this->name], $file, $this->getFolderName());
     if ($this->upload->isError()) {
         return false;
     }
     if ($this->relationAutoSetting) {
         if (!$objectClass) {
             return false;
         }
         $file = $this->upload->getFile();
         $record->{$this->name . 'ID'} = $file->ID;
     }
     return $this;
 }