/** * Sets the value of this form field to a set of File IDs * * @param mixed $value If an array, use that as a list of the IDs, if not, extract it from the DataObject * @param mixed $data The DataObject being updated by the form */ public function setValue($value = null, $data = null) { if(!is_array($value)) { if(!$value && $data && $data instanceof DataObject && $data->hasMethod($this->name)) { $funcName = $this->name; if($obj = $data->$funcName()) { if($obj instanceof DataObjectSet) { $value = $obj->column('ID'); } } } } parent::setValue($value, $data); }
/** * Sets the value of the form field. * * @param mixed $value If numeric, get the file by ID, otherwise, introspect the $data object * @param DataObject $data The record associated with the parent form */ public function setValue($value = null, $data = null) { if (!is_numeric($value)) { if ($id = Controller::curr()->getRequest()->requestVar($this->Name() . "ID")) { $value = $id; } elseif (!$value && $data && $data instanceof DataObject && $data->hasMethod($this->name)) { $funcName = $this->name; if ($obj = $data->{$funcName}()) { if ($obj instanceof File || $obj instanceof S3File) { $value = $obj->ID; } } } } parent::setValue($value, $data); }