public function saveInto(DataObjectInterface $record)
 {
     if ($this->name) {
         $value = $this->dataValue();
         $file = null;
         if ($value['id']) {
             $file = CloudinaryFile::get()->byID($value['id']);
         }
         if (!$file) {
             $file = new CloudinaryFile();
         }
         if ($value['resource_type'] == 'image') {
             $file->ClassName = 'CloudinaryImage';
         }
         if ($value['url']) {
             $file->update(array('CloudinaryURL' => $value['url'], 'Title' => $value['title'], 'Size' => $value['size'], 'FileName' => $value['filename'], 'ResourceType' => $value['resource_type'], 'Height' => (int) $value['height'], 'Width' => (int) $value['width'], 'Format' => $value['format']));
             $file->write();
             $record->setCastedField($this->name . 'ID', $file->ID);
         } else {
             if ($file->exists()) {
                 $file->delete();
             }
             $record->setCastedField($this->name . 'ID', 0);
         }
     }
 }
 public function saveInto(DataObjectInterface $record)
 {
     $schemas = $record->getSchemas();
     $value = $this->Value();
     $metadata = array();
     foreach ($schemas as $schema) {
         $metadata[$schema->Name] = array();
         $fields = $schema->getFormFields();
         $namesMap = array();
         foreach ($fields as $field) {
             $brPos = strrpos($field->getName(), '[');
             $name = substr($field->getName(), $brPos + 1, -1);
             $namesMap[$field->getName()] = $name;
         }
         if (isset($value[$schema->Name])) {
             foreach ($fields as $field) {
                 $fName = $field->getName();
                 $sName = $namesMap[$fName];
                 if (array_key_exists($sName, $value[$schema->Name])) {
                     $field->setValue($value[$schema->Name][$sName], $value[$schema->Name]);
                 } else {
                     $field->setValue(null);
                 }
             }
         }
         foreach ($fields as $field) {
             $name = $namesMap[$field->getName()];
             $schemaField = $schema->Fields()->find('Name', $name);
             $toSave = $schemaField->processBeforeWrite($field->dataValue(), $record);
             $metadata[$schema->Name][$name] = $toSave;
         }
     }
     $record->{$this->name} = serialize($metadata);
 }
Exemple #3
0
 public function saveInto(DataObjectInterface $record)
 {
     $isNew = !$record->exists();
     parent::saveInto($record);
     // if we're dealing with an unsaved record, we have to rebuild the relation list
     // with the proper meny_many_extraFields attributes (eg. the sort order)
     if ($isNew) {
         // we have to grab the raw post data as the data is in the right order there.
         // this is kind of a hack, but we simply lack the information about the client-side sorting otherwise
         if (isset($_POST[$this->name]) && isset($_POST[$this->name]['Files']) && is_array($_POST[$this->name]['Files'])) {
             $idList = $_POST[$this->name]['Files'];
         } else {
             // take the ItemIDs as a fallback
             $idList = $this->getItemIDs();
         }
         $sortColumn = $this->getSortColumn();
         $relationName = $this->getName();
         if ($relationName && $record->many_many($relationName) !== null && ($list = $record->{$relationName}())) {
             $arrayList = $list->toArray();
             foreach ($arrayList as $item) {
                 $list->remove($item);
                 $list->add($item, array($sortColumn => array_search($item->ID, $idList) + 1));
             }
         }
     }
 }
 public function saveInto(\DataObjectInterface $record)
 {
     if (!$this->dataValue()) {
         return;
     }
     $record->setCastedField('AdministrativeArea', BelgianGeoUtils::getProvinceRegion($this->dataValue()));
     return parent::saveInto($record);
 }
 public function saveInto(DataObjectInterface $record)
 {
     $value = $this->value;
     $fieldName = $this->getName();
     if ($record->has_one($fieldName)) {
         $record->{$fieldName . 'ID'} = $value;
     }
     return $this;
 }
 /**
  * SaveInto checks if set-methods are available and use them instead of setting the values directly. saveInto
  * initiates a new LinkField class object to pass through the values to the setter method.
  */
 function saveInto(DataObjectInterface $dataObject)
 {
     $fieldName = $this->name;
     if ($dataObject->hasMethod("set{$fieldName}")) {
         $dataObject->{$fieldName} = DBField::create('AlternativeField', array("SelectedValue" => $this->fieldSelectedValue->Value(), "AlternativeValue" => $this->fieldAlternativeValue->Value()));
     } else {
         $dataObject->{$fieldName}->setSelectedValue($this->fieldSelectedValue->Value());
         $dataObject->{$fieldName}->setAlternativeValue($this->fieldAlternativeValue->Value());
     }
 }
 /**
  * SaveInto checks if set-methods are available and use them instead of setting the values directly. saveInto
  * initiates a new LinkField class object to pass through the values to the setter method.
  */
 public function saveInto(DataObjectInterface $dataObject)
 {
     $fieldName = $this->name;
     if ($dataObject->hasMethod("set{$fieldName}")) {
         $dataObject->{$fieldName} = DBField::create('LinkField', array("PageID" => $this->fieldPageID->Value(), "CustomURL" => $this->fieldCustomURL->Value()));
     } else {
         $dataObject->{$fieldName}->setPageID($this->fieldPageID->Value());
         $dataObject->{$fieldName}->setCustomURL($this->fieldCustomURL->Value());
     }
 }
 public function saveInto(\DataObjectInterface $record)
 {
     if ($this->name) {
         $castingHelper = $record->castingHelper($this->name);
         if ($castingHelper == 'Boolean') {
             $record->setCastedField($this->name, $this->getBooleanValue());
         } else {
             $record->setCastedField($this->name, $this->dataValue());
         }
     }
 }
 /**
  * Save value to dataobject
  *
  * @see forms/CheckboxSetField::saveInto()
  */
 public function saveInto(DataObjectInterface $record)
 {
     $fieldName = $this->getName();
     $valueArray = is_array($this->value) && isset($this->value[0]) && strpos($this->value[0], ',') ? explode(',', $this->value[0]) : $this->value;
     if ($fieldName && ($record->has_many($fieldName) || $record->many_many($fieldName))) {
         // Set related records
         $record->{$fieldName}()->setByIDList($valueArray);
     } else {
         $record->{$fieldName} = is_array($this->value) ? implode(',', $this->value) : $this->value;
         $record->write();
     }
 }
 function saveInto(DataObjectInterface $record)
 {
     $fieldName = $this->name;
     $fieldNameID = $fieldName . 'ID';
     $record->{$fieldNameID} = 0;
     if ($val = $this->value[$this->htmlListField]) {
         if ($val != 'undefined') {
             $record->{$fieldNameID} = $val;
         }
     }
     $record->write();
 }
 public function saveInto(\DataObjectInterface $record)
 {
     $fieldname = $this->name;
     $relation = $fieldname && $record && $record->hasMethod($fieldname) ? $record->{$fieldname}() : null;
     $value = $this->dataValue();
     if ($relation) {
         // TODO: Save to relation
     } else {
         if (is_array($value)) {
             $this->value = json_encode(array_values($value));
         }
     }
     parent::saveInto($record);
 }
 /**
  * @param string $name
  * @param string $title
  * @param DataObjectInterface $object
  * @param string $sort
  * @param SS_List $source
  * @param string $titleField
  */
 public function __construct($name, $title, DataObjectInterface $object, $sort = false, SS_List $source = null, $titleField = 'Title')
 {
     $this->setSort($sort);
     if ($object->many_many($name)) {
         $dataSource = $object->{$name}();
         // Check if we're dealing with an UnsavedRelationList
         $unsaved = $dataSource instanceof UnsavedRelationList;
         // Store the relation's class name
         $class = $dataSource->dataClass();
         $this->dataClass = $class;
         // Sort the items
         if ($this->getSort()) {
             $dataSource = $dataSource->sort($this->getSort());
         }
         // If we're dealing with an UnsavedRelationList, it'll be empty, so we
         // can skip this and just use an array of all available items
         if ($unsaved) {
             $dataSource = $class::get()->map()->toArray();
         } else {
             // If we've been given a list source, filter on those IDs only.
             if ($source) {
                 $dataSource = $dataSource->filter('ID', $source->column('ID'));
             }
             // Start building the data source from scratch. Currently selected items first,
             // in the correct sort order
             $dataSource = $dataSource->map('ID', $titleField)->toArray();
             // Get the other items
             $theRest = $class::get();
             // Exclude items that we've already found
             if (!empty($dataSource)) {
                 $theRest = $theRest->exclude('ID', array_keys($dataSource));
             }
             // If we've been given a list source, filter on those IDs only
             if ($source) {
                 $theRest = $theRest->filter('ID', $source->column('ID'));
             }
             $theRest = $theRest->map('ID', $titleField)->toArray();
             // ... we then add the remaining items in whatever order they come
             $dataSource = $dataSource + $theRest;
         }
     } elseif ($source instanceof SS_List) {
         $dataSource = $source->map('ID', $titleField)->toArray();
     } elseif (is_array($source) && ArrayLib::is_associative($source)) {
         $dataSource = $source;
     } else {
         user_error('MultiSelectField::__construct(): MultiSelectField only supports many-to-many relations');
     }
     parent::__construct($name, $title, $dataSource, '', null, true);
 }
 /**
  * 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.
  *
  */
 function saveInto(DataObjectInterface $dataObject)
 {
     $fieldName = $this->name;
     if ($dataObject->hasMethod("set{$fieldName}")) {
         $dataObject->{$fieldName} = DBField::create_field('WTLink', array("Type" => $this->fieldType->Value(), "Internal" => $this->internalField->Value(), "External" => $this->externalField->Value(), "Email" => $this->emailField->Value(), "File" => $this->fileField->Value(), "TargetBlank" => $this->targetBlankField->Value()));
     } else {
         if (!empty($dataObject->{$fieldName})) {
             $dataObject->{$fieldName}->setType($this->fieldType->Value());
             $dataObject->{$fieldName}->setInternal($this->internalField->Value());
             $dataObject->{$fieldName}->setExternal($this->externalField->Value());
             $dataObject->{$fieldName}->setEmail($this->emailField->Value());
             $dataObject->{$fieldName}->setFile($this->fileField->Value());
             $dataObject->{$fieldName}->setTargetBlank($this->targetBlankField->Value());
         }
     }
 }
 /**
  * Called when a grid field is saved, converts the StatefulGridFieldList to a RelationList
  * @param {GridField} $field
  * @param {DataObjectInterface} $record
  */
 public function handleSave(GridField $grid, DataObjectInterface $record)
 {
     $list = $grid->getList();
     if ($list instanceof StatefulGridFieldList) {
         $relationName = $list->getRelationName();
         if ($record->has_many($relationName)) {
             $list->changeToList($record->getComponents($list->getRelationName()));
         } else {
             if ($record->many_many($relationName)) {
                 $list->changeToList($record->getManyManyComponents($list->getRelationName()));
             } else {
                 throw new InvalidArgumentException('Record does not have a has_many or many_many relationship called "' . $relationName . '"', null, null);
             }
         }
     }
 }
 public function __construct($controller, $name, DataObjectInterface $object)
 {
     $this->object = $object;
     $fields = $object->getFrontEndFields(array(get_class($object) => $object));
     $fields->push(new HiddenField("ID", "ID"));
     $actions = new FieldList(new FormAction("save", "Save " . $object->i18n_singular_name()));
     parent::__construct($controller, $name, $fields, $actions);
     $object->extend('updateEditComponentForm', $this);
     if ($this->object->isInDB()) {
         $this->loadDataFrom($this->object);
     }
     //all fields are required
     if (!$this->validator) {
         $this->setValidator(new RequiredFields(array_keys($fields->saveableFields())));
     }
 }
 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.');
     }
     $htmlValue = Injector::inst()->create('HTMLValue', $this->value);
     // Sanitise if requested
     if ($this->config()->sanitise_server_side) {
         $santiser = Injector::inst()->create('HtmlEditorSanitiser', HtmlEditorConfig::get_active());
         $santiser->sanitise($htmlValue);
     }
     // Resample images and add default attributes
     if ($images = $htmlValue->getElementsByTagName('img')) {
         foreach ($images as $img) {
             // strip any ?r=n data from the src attribute
             $img->setAttribute('src', preg_replace('/([^\\?]*)\\?r=[0-9]+$/i', '$1', $img->getAttribute('src')));
             // Resample the images if the width & height have changed.
             if ($image = File::find(urldecode(Director::makeRelative($img->getAttribute('src'))))) {
                 $width = (int) $img->getAttribute('width');
                 $height = (int) $img->getAttribute('height');
                 if ($width && $height && ($width != $image->getWidth() || $height != $image->getHeight())) {
                     //Make sure that the resized image actually returns an image:
                     $resized = $image->ResizedImage($width, $height);
                     if ($resized) {
                         $img->setAttribute('src', $resized->getRelativePath());
                     }
                 }
             }
             // Add default empty title & alt attributes.
             if (!$img->getAttribute('alt')) {
                 $img->setAttribute('alt', '');
             }
             if (!$img->getAttribute('title')) {
                 $img->setAttribute('title', '');
             }
             // Use this extension point to manipulate images inserted using TinyMCE, e.g. add a CSS class, change default title
             // $image is the image, $img is the DOM model
             $this->extend('processImage', $image, $img);
         }
     }
     // 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)
 {
     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.');
     }
     // Resample images
     $value = Image::regenerate_html_links($this->value);
     $htmlValue = Injector::inst()->create('HTMLValue', $value);
     // Sanitise if requested
     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();
 }
 /**
  * SaveInto checks if set-methods are available and use them instead of setting the values directly. saveInto
  * initiates a new LinkField class object to pass through the values to the setter method.
  */
 public function saveInto(DataObjectInterface $dataObject)
 {
     $db_field = $dataObject->dbObject($this->name);
     $type = $this->composite_fields['Type']->Value();
     $db_field->setLinkType($type);
     if (isset($this->composite_fields[$type])) {
         $db_field->setLinkValue($this->composite_fields[$type]->Value());
     }
 }
 public function saveInto(DataObjectInterface $record)
 {
     if ($this->name) {
         $tags = explode(',', $this->dataValue());
         if (!$record instanceof SummitEvent) {
             return;
         }
         $record->Tags()->removeAll();
         foreach ($tags as $t) {
             $tag = Tag::get()->filter('Tag', $t)->first();
             if (is_null($tag)) {
                 $tag = Tag::create(array('Tag' => $t));
                 $tag->write();
             }
             $record->Tags()->add($tag);
         }
     }
 }
 /**
  * @param DataObjectInterface $record
  * @return $this|void
  * if ColorPicker field exists, then convert the value hex to rgb
  */
 public function saveInto(DataObjectInterface $record)
 {
     $name = $this->getName();
     if ($this->ColorPickerExists() && $record->db($name)) {
         $record->{"{$name}"} = $this->value ? 'rgb(' . implode(',', $this->hex2rgb($this->value)) . ')' : null;
     } elseif ($record->db($name)) {
         $record->{"{$name}"} = $this->value;
     }
     return $this;
 }
Exemple #21
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)
  */
 public function saveInto(DataObjectInterface $dataObject)
 {
     $fieldName = $this->name;
     if ($dataObject->hasMethod("set{$fieldName}")) {
         $dataObject->{$fieldName} = DBField::create_field('Money', array("Currency" => $this->fieldCurrency->dataValue(), "Amount" => $this->fieldAmount->dataValue()));
     } else {
         $dataObject->{$fieldName}->setCurrency($this->fieldCurrency->dataValue());
         $dataObject->{$fieldName}->setAmount($this->fieldAmount->dataValue());
     }
 }
 /**
  * 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)
  */
 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();
     }
 }
Exemple #23
0
 /**
  * Save the contents of this form into the given data object.
  * It will make use of setCastedField() to do this.
  *
  * @param $dataObject The object to save data into
  * @param $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.
  */
 function saveInto(DataObjectInterface $dataObject, $fieldList = null)
 {
     $dataFields = $this->fields->saveableFields();
     $lastField = null;
     $config = HTMLPurifier_Config::createDefault();
     // Remove any CSS or inline styles
     $config->set('CSS.AllowedProperties', array());
     $purifier = new HTMLPurifier($config);
     if ($dataFields) {
         foreach ($dataFields as $field) {
             // Skip fields that have been excluded
             if ($fieldList && is_array($fieldList) && !in_array($field->Name(), $fieldList)) {
                 continue;
             }
             $saveMethod = "save{$field->getName()}";
             //purify
             $value = $field->dataValue();
             $class = get_class($field);
             if (is_string($value) && ($class == 'TextField' || $class == "TextareaField")) {
                 $field->setValue($purifier->purify($value));
             }
             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);
     }
 }
 /**
  * SaveInto checks if set-methods are available and use them instead of setting the values directly. saveInto
  * initiates a new LinkField class object to pass through the values to the setter method.
  */
 public function saveInto(DataObjectInterface $dataObject)
 {
     $fieldName = $this->name;
     if ($dataObject->hasMethod("set{$fieldName}")) {
         $dataObject->{$fieldName} = DBField::create('NamedLinkField', array("PageID" => $this->fieldPageID->Value(), "CustomURL" => $this->fieldCustomURL->Value(), "Title" => $this->fieldTitle->Value(), "Linkmode" => $this->fieldLinkmode->Value()));
     } else {
         if (!is_object($dataObject->{$fieldName})) {
             $dataObject->{$fieldName} = NamedLinkField::create();
         }
         $dataObject->{$fieldName}->setPageID($this->fieldPageID->Value());
         $dataObject->{$fieldName}->setCustomURL($this->fieldCustomURL->Value());
         $dataObject->{$fieldName}->setTitle($this->fieldTitle->Value());
         $dataObject->{$fieldName}->setLinkmode($this->fieldLinkmode->Value());
     }
 }
Exemple #25
0
 /**
  * @param int $lineNumber
  *
  * @return BlockInterface|mixed|null|string
  */
 protected function grabReferences($lineNumber)
 {
     $content = $this->dataObject->getLine($lineNumber);
     // grab urls with title
     $content = preg_replace_callback('/\\[(.*)\\]:\\s?(.*)\\s?"(.*)"/U', function ($found) {
         $key = trim($found[1]);
         $url = trim($found[2]);
         $title = trim($found[3]);
         $this->dataObject->addReference($key, ['url' => $url, 'title' => $title, 'type' => 'url']);
         return '';
     }, $content);
     // grab urls without title
     $content = preg_replace_callback('/\\[(.*)\\]:\\s?(.*)/', function ($found) {
         $key = trim($found[1]);
         $url = trim($found[2]);
         $this->dataObject->addReference($key, ['url' => $url, 'title' => '', 'type' => 'url']);
         return '';
     }, $content);
     return $content;
 }
 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);
     }
 }
 /**
  *
  * TO DO: explain how this works or what it does.
  */
 public function saveInto(DataObjectInterface $record)
 {
     if ($this->value !== 'unchanged') {
         $items = array();
         $fieldName = $this->name;
         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;
             }
         }
         if ($fieldName && ($record->has_many($fieldName) || $record->many_many($fieldName))) {
             // Set related records
             $record->{$fieldName}()->setByIDList($items);
         } else {
             $record->{$fieldName} = implode(',', $items);
         }
     }
 }
 public function saveInto(DataObjectInterface $record)
 {
     if ($record->hasMethod("set{$this->name}")) {
         $values = [];
         foreach ($this->children as $point => $field) {
             $values[$point] = $field[$point]->Value();
         }
         $record->{$this->name} = DBField::create_field('Milkyway\\SS\\FocusArea\\DBField', $values);
     } else {
         foreach ($this->children as $point => $field) {
             $record->{$this->name}->{$point} = $field->Value();
         }
     }
 }
 /**
  * Save the current value of this CheckboxSetField 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 $record The record to save into
  */
 public function saveInto(DataObjectInterface $record)
 {
     $fieldname = $this->name;
     $relation = $fieldname && $record && $record->hasMethod($fieldname) ? $record->{$fieldname}() : null;
     if ($fieldname && $record && $relation && ($relation instanceof RelationList || $relation instanceof UnsavedRelationList)) {
         $idList = array();
         if ($this->value) {
             foreach ($this->value as $id => $bool) {
                 if ($bool) {
                     $idList[] = $id;
                 }
             }
         }
         $relation->setByIDList($idList);
     } elseif ($fieldname && $record) {
         if ($this->value) {
             $this->value = str_replace(',', '{comma}', $this->value);
             $record->{$fieldname} = implode(',', (array) $this->value);
         } else {
             $record->{$fieldname} = '';
         }
     }
 }
 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.');
     }
     $htmlValue = Injector::inst()->create('HTMLValue', $this->value);
     // Sanitise if requested
     if ($this->config()->sanitise_server_side) {
         $santiser = Injector::inst()->create('HtmlEditorSanitiser', HtmlEditorConfig::get_active());
         $santiser->sanitise($htmlValue);
     }
     // Resample images and add default attributes
     if ($images = $htmlValue->getElementsByTagName('img')) {
         foreach ($images as $img) {
             // strip any ?r=n data from the src attribute
             $img->setAttribute('src', preg_replace('/([^\\?]*)\\?r=[0-9]+$/i', '$1', $img->getAttribute('src')));
             // Resample the images if the width & height have changed.
             // TODO: look for -10x here?
             $filename = RetinaImage::removeFilenameAppender(urldecode(Director::makeRelative($img->getAttribute('src'))), '-10x');
             $image = File::find($filename);
             // try to find it using the legacy way
             if (!$image) {
                 $image = File::find(urldecode(Director::makeRelative($img->getAttribute('src'))));
             }
             if ($image) {
                 $imagemap = $image->toMap();
                 $retinaimage = RetinaImage::create();
                 foreach ($imagemap as $key => $value) {
                     $retinaimage->{$key} = $value;
                 }
                 $width = $img->getAttribute('width');
                 $height = $img->getAttribute('height');
                 if ($width && $height && ($width != $retinaimage->getWidth() || $height != $retinaimage->getHeight()) || !$img->hasAttribute('srcset') && RetinaImage::$forceretina) {
                     //Make sure that the resized image actually returns an image:
                     if (!is_numeric($width) || !is_numeric($height)) {
                         $width = (int) ($retinaimage->getWidth() / 2);
                         $height = (int) ($retinaimage->getHeight() / 2);
                     }
                     $resized = $retinaimage->ResizedImage($width, $height);
                     $url = $resized->getRelativePath();
                     $onex10 = $retinaimage->insertFilenameAppender($url, '-10x');
                     $onex15 = $retinaimage->insertFilenameAppender($url, '-15x');
                     $onex20 = $retinaimage->insertFilenameAppender($url, '-20x');
                     if ($resized) {
                         $img->setAttribute('src', $onex10);
                     }
                     // srcset=\"$onex10 1x, $onex15 1.5x, $onex20 2x\"
                     $img->setAttribute('srcset', "{$onex10} 1x, {$onex15} 1.5x, {$onex20} 2x");
                 }
             }
             // Add default empty title & alt attributes.
             if (!$img->getAttribute('alt')) {
                 $img->setAttribute('alt', '');
             }
             if (!$img->getAttribute('title')) {
                 $img->setAttribute('title', '');
             }
         }
     }
     // Store into record
     $record->{$this->name} = $htmlValue->getContent();
 }