public function scaffoldFormField($title = null, $params = null) { $titleField = $this->object->hasField('Title') ? 'Title' : 'Name'; $map = DataList::create(get_class($this->object))->map('ID', $titleField); $field = new DropdownField($this->name, $title, $map); $field->setEmptyString(' '); return $field; }
/** * Get the list of extra data from the $record as saved into it by * {@see Form::saveInto()} * * Handles detection of falsey values explicitly saved into the * DataObject by formfields * * @param DataObject $record * @param SS_List $list * @return array List of data to write to the relation */ protected function getExtraSavedData($record, $list) { // Skip extra data if not ManyManyList if (!$list instanceof ManyManyList) { return null; } $data = array(); foreach ($list->getExtraFields() as $field => $dbSpec) { $savedField = "ManyMany[{$field}]"; if ($record->hasField($savedField)) { $data[$field] = $record->getField($savedField); } } return $data; }
/** * Gets a writer for a DataObject * * If the field already has a value, a writer is created matching that * identifier. Otherwise, a new writer is created based on either * * - The $type passed in * - whether the $object class specifies a prefered storage type via * getEffectiveContentStore * - what the `defaultStore` is set to for the content service * * * @param DataObject $object * The object to get a writer for * @param String $field * The field being written to * @param String $type * Explicitly state what the content store type will be * @return ContentWriter */ public function getWriterFor(DataObject $object = null, $field = 'FilePointer', $type = null) { if ($object && $field && $object->hasField($field)) { $val = $object->{$field}; if (strlen($val)) { $reader = $this->getReader($val); if ($reader && $reader->isReadable()) { return $reader->getWriter(); } } } if (!$type) { // specifically expecting to be handling File objects, but allows other // objects to play too if ($object && $object->hasMethod('getEffectiveContentStore')) { $type = $object->getEffectiveContentStore(); } else { $type = $this->defaultStore; } } // looks like we're getting a writer with no underlying file (as yet) return $this->getWriter($type); }
/** * Returns all fields on the object which should be shown * in the output. Can be customised through {@link self::setCustomFields()}. * * @todo Allow for custom getters on the processed object (currently filtered through inheritedDatabaseFields) * @todo Field level permission checks * * @param DataObject $obj * @return array */ protected function getFieldsForObj($obj) { $dbFields = array(); // if custom fields are specified, only select these if(is_array($this->customFields)) { foreach($this->customFields as $fieldName) { // @todo Possible security risk by making methods accessible - implement field-level security if($obj->hasField($fieldName) || $obj->hasMethod("get{$fieldName}")) $dbFields[$fieldName] = $fieldName; } } else { // by default, all database fields are selected $dbFields = $obj->inheritedDatabaseFields(); } if(is_array($this->customAddFields)) { foreach($this->customAddFields as $fieldName) { // @todo Possible security risk by making methods accessible - implement field-level security if($obj->hasField($fieldName) || $obj->hasMethod("get{$fieldName}")) $dbFields[$fieldName] = $fieldName; } } // add default required fields $dbFields = array_merge($dbFields, array('ID'=>'Int')); // @todo Requires PHP 5.1+ if(is_array($this->removeFields)) { $dbFields = array_diff_key($dbFields, array_combine($this->removeFields,$this->removeFields)); } return $dbFields; }
public function scaffoldFormField($title = null, $params = null) { $titleField = ($this->object->hasField('Title')) ? "Title" : "Name"; $map = DataList::create(get_class($this->object))->map("ID", $titleField); return new DropdownField($this->name, $title, $map, null, null, ' '); }
public function scaffoldFormField($title = null, $params = null) { $titleField = ($this->object->hasField('Title')) ? "Title" : "Name"; $map = new SQLMap($this->object->extendedSQL(), "ID", $titleField); return new DropdownField($this->name, $title, $map, null, null, ' '); }
/** * @desc */ function saveInto(DataObject $record) { $fieldname = $this->name; if ($fieldname && $record && ($record->has_many($fieldname) || $record->many_many($fieldname))) { $record->{$fieldname}()->setByIDList($this->value); } else { if ($fieldname && $record && $record->hasField($fieldname)) { if ($this->value) { $this->value = str_replace(",", "{comma}", $this->value); $record->{$fieldname} = implode(",", $this->value); } else { $record->{$fieldname} = ''; } } } }