CMS  Version 3.9
SettingAutoForm Class Reference
+ Inheritance diagram for SettingAutoForm:

Public Member Functions

 SettingAutoForm ($component, $filter=null)
 
 buildForm ($component_id=0)
 
 writeSettings ($settings)
 
 save ()
 

Public Attributes

 $settings
 
 $customSettings = array()
 
 $filter = null
 

Detailed Description

Definition at line 41 of file setting_auto_form.inc.

Member Function Documentation

◆ buildForm()

SettingAutoForm::buildForm (   $component_id = 0)

Definition at line 62 of file setting_auto_form.inc.

63  {
64  $componentSettings = new ComponentSettings();
65 
66  $fields = array();
67 
68  foreach($this->settings as $setting)
69  {
70  if ($this->filter && $this->filter->isExcluded($setting->name)) continue;
71 
72  $fields[$setting->name] = ($setting->field_type) ? $setting->field_type : "String";
73  if ($setting->weight < 0) $this->hide($setting->name);
74  if ($setting->category) $this->group($setting->category, $setting->name);
75 
76  }
77 
78  $componentSettings->fields = $fields;
79  parent::AutoForm($componentSettings, "POST", "?component_id={$component_id}");
80 
81  foreach($this->settings as $setting)
82  {
83  if ($this->filter && $this->filter->isExcluded($setting->name)) continue;
84 
85  $this->data->set($setting->name, $setting->value);
86  if($setting->annotation)
87  $this->annotate($setting->name, $setting->annotation);
88 
89  /*
90  * Create custom renderers. If option is not
91  * a custom renderer name, then assume it is
92  * a set of options for SelectFieldRenderer.
93  */
94  if($setting->options == "FileUploadFieldRenderer")
95  {
96  $renderers[$setting->settings_id] = new FileUploadFieldRenderer($this, $setting->name, prettify($setting->name), uploadSettingFile);
97  $this->annotate($setting->name, "<a href='/action/settings/download?setting_id={$setting->settings_id}'>{$setting->value}</a>");
98 
99  }
100  else if ($setting->options == "Permissions")
101  {
102  $renderer = new ChecklistFieldRenderer($this, $setting->name, $setting->annotation ? $setting->annotation : prettify($setting->name), SiteRole::getRolesArray());
103  if ($setting->annotation) $this->annotate($setting->name, "");
104  $renderer->dropdown = true;
105  $renderer->setSize(200, 100);
106  $renderer->dropdownMaxWidth = 500;
107  $renderer->dropdownMessage = "Select User Roles";
108  }
109  else if($setting->options)
110  {
111  $optionList = $setting->formatOptionList();
112  if(isset($optionList))
113  $renderers[$setting->settings_id] = new SelectFieldRenderer($this, $setting->name, prettify($setting->name), $optionList);
114  }
115  }
116 
117  $extension = SettingsManager::getExtension($this->component->name);
118  if ($extension)
119  {
120  call_user_func($extension, $this);
121  }
122 
123  $this->submitLabel = "Save Changes";
124  }
$table filter
if(!Settings::getValue("blog", "enable_extended_subscription_fields")) $form submitLabel
$extension
Definition: upload.inc:70
Dummy data model to render a component's settings as a form, using the "type" field of the setting re...
Definition: settings.inc:379
static getExtension($component)
static getRolesArray()
Retrieves the array of roles and their names for the current site for use in a CMS form.
Definition: role.inc:75
if( $method=="POST")
uploadSettingFile($field, $setting)
$renderer
$setting

◆ save()

SettingAutoForm::save ( )

Definition at line 144 of file setting_auto_form.inc.

145  {
146  $this->patchUpReferences();
147 
148  $this->configureValidators();
149 
150  $obj =& $this->data;
151  $obj->fromPOST();
152 
153  if (isset($_POST["#FORMID#"]))
154  {
155  $this->id = $_POST["#FORMID#"];
156  }
157 
158  $this->msg = $this->validator->validate();
159  if ($this->msg != "") return false;
160 
161  $this->preProcessFields($pk, $filter);
162 
163  $indexedSettings = reindexList($this->settings, "name");
164 
165  foreach($obj->getFields() as $name => $type)
166  {
167  if(array_key_exists($name, $indexedSettings))
168  {
169  $setting = $indexedSettings[$name];
170  $setting->value = $obj->$name;
171  $setting->filter = new InclusionFilter("value");
172  $setting->save();
173  Cache::put("setting_{$setting->component}_{$setting->name}", $setting->value);
174 
175  }
176  }
177  Cache::invalidate("auto_form_defaults");
178  Cache::invalidate("config");
179 
180  // onComplete event is fired once all processing has been completed
181 
182  if ($this->onSaveComplete)
183  {
184  call_user_func_array($this->onSaveComplete, array($this));
185  }
186 
187  trace("Settings auto form returning true", 3);
188 
189  ComponentManager::fireEventTo($this->component->name, "ClearCache");
190 
191  return true;
192  }
$_POST["owner_id"]
Definition: blog_form.inc:54
$name
Definition: upload.inc:54
static fireEventTo($event, $component, $parameter=null)
Fire an event to the specificed component.
$form onSaveComplete

◆ SettingAutoForm()

SettingAutoForm::SettingAutoForm (   $component,
  $filter = null 
)

Definition at line 46 of file setting_auto_form.inc.

47  {
48  $this->filter = $filter;
49 
50  ComponentManager::fireEvent("RegisterSettingsFormExtension");
51 
52  $this->component = $component;
53 
54  $this->settings = Query::create(Settings, "WHERE component=:component ORDER BY category, weight, name")
55  ->bind(":component", $component->name)
56  ->execute();
57 
58  $this->buildForm($component->component_id);
59 
60  }
$component
Definition: help.inc:38
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
buildForm($component_id=0)
The Settings class provides components with a common API for specifying application settings and conf...
Definition: settings.inc:49

◆ writeSettings()

SettingAutoForm::writeSettings (   $settings)

Definition at line 126 of file setting_auto_form.inc.

127  {
128  foreach($settings as $setting)
129  {
130  if(array_key_exists($setting->field_type, Settings::$customTypes))
131  {
132  $type = Settings::$customTypes[$setting->field_type];
134  }
135  else
136  $type = ($setting->field_type) ? $setting->field_type : "String";
137 
138  $fields[$setting->name] = $type;
139  }
140 
141  return $fields;
142  }

Member Data Documentation

◆ $customSettings

SettingAutoForm::$customSettings = array()

Definition at line 44 of file setting_auto_form.inc.

◆ $filter

SettingAutoForm::$filter = null

Definition at line 45 of file setting_auto_form.inc.

◆ $settings

SettingAutoForm::$settings

Definition at line 43 of file setting_auto_form.inc.


The documentation for this class was generated from the following file: