mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
ENHANCEMENT: moving userdefinedform fields to using Settings column rather then each field having its own table
This commit is contained in:
parent
d592ed005f
commit
ff97a5ab57
@ -20,6 +20,7 @@ class EditableFormField extends DataObject {
|
||||
"CustomErrorMessage" => "Varchar(255)",
|
||||
"CustomRules" => "Text",
|
||||
"ShowOnLoad" => "Boolean",
|
||||
"CustomSettings" => "Text"
|
||||
);
|
||||
|
||||
static $defaults = array(
|
||||
@ -72,6 +73,43 @@ class EditableFormField extends DataObject {
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
/**
|
||||
* To prevent having tables for each fields minor settings we store it as
|
||||
* a serialized array in the database.
|
||||
*
|
||||
* @return Array Return all the Settings
|
||||
*/
|
||||
protected function getFieldSettings() {
|
||||
return (isset($this->CustomSettings)) ? unserialize($this->CustomSettings) : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the custom settings for this field as we store the minor details in
|
||||
* a serialized array in the database
|
||||
*
|
||||
* @param Array the custom settings
|
||||
*/
|
||||
protected function setFieldSettings($settings = array()) {
|
||||
$this->CustomSettings = serialize($settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return just one custom setting or empty string if it does
|
||||
* not exist
|
||||
*
|
||||
* @param String Value to use as key
|
||||
* @return String
|
||||
*/
|
||||
protected function getSetting($setting) {
|
||||
$settings = $this->getFieldSettings();
|
||||
if(isset($settings) && count($settings) > 0) {
|
||||
if(isset($settings[$setting])) {
|
||||
return $settings[$setting];
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the icon for this field type, relative to the site root.
|
||||
*
|
||||
@ -205,8 +243,14 @@ class EditableFormField extends DataObject {
|
||||
$this->Name = $this->class.$this->ID;
|
||||
$this->CustomErrorMessage = (isset($data['CustomErrorMessage'])) ? $data['CustomErrorMessage'] : "";
|
||||
$this->CustomRules = "";
|
||||
$this->CustomSettings = "";
|
||||
$this->ShowOnLoad = (isset($data['ShowOnLoad']) && $data['ShowOnLoad'] == "Show") ? 1 : 0;
|
||||
|
||||
// custom settings
|
||||
if(isset($data['CustomSettings'])) {
|
||||
$this->setFieldSettings($data['CustomSettings']);
|
||||
}
|
||||
|
||||
// custom validation
|
||||
if(isset($data['CustomRules'])) {
|
||||
$rules = array();
|
||||
|
@ -66,10 +66,9 @@ class FieldEditor extends FormField {
|
||||
foreach($fields as $field => $title) {
|
||||
// get the nice title and strip out field
|
||||
$niceTitle = trim(str_ireplace("Field", "", eval("return $title::\$singular_name;")));
|
||||
$title = trim(str_ireplace("Editable", "", $title));
|
||||
if($title != 'MultipleOptionField') {
|
||||
$output->push(new ArrayData(array(
|
||||
'ClassName' => $title,
|
||||
'ClassName' => $field,
|
||||
'Title' => "$niceTitle"
|
||||
)));
|
||||
}
|
||||
@ -157,8 +156,8 @@ class FieldEditor extends FormField {
|
||||
$highestSort = DB::query("SELECT MAX(Sort) FROM EditableFormField WHERE ParentID = '$parentID'");
|
||||
$sort = $highestSort->value() + 1;
|
||||
|
||||
$className = "Editable" . ucfirst($_REQUEST['Type']);
|
||||
$name = $this->name;
|
||||
$className = (isset($_REQUEST['Type'])) ? $_REQUEST['Type'] : '';
|
||||
|
||||
if(is_subclass_of($className, "EditableFormField")) {
|
||||
$field = new $className();
|
||||
$field->write();
|
||||
|
Loading…
Reference in New Issue
Block a user