Permalink
Browse files

MDL-38735 backup: add missing setType() to forms

  • Loading branch information...
1 parent d8201d4 commit 5ae69b2aeda69af64802d44e301cd82d34ebf29d @stronk7 stronk7 committed Apr 3, 2013
@@ -28,6 +28,7 @@ function definition() {
$mform =& $this->_form;
$contextid = $this->_customdata['contextid'];
$mform->addElement('hidden', 'contextid', $contextid);
+ $mform->setType('contextid', PARAM_INT);
$mform->addElement('filepicker', 'backupfile', get_string('files'));
$submit_string = get_string('restore');
$this->add_action_buttons(false, $submit_string);
@@ -404,6 +404,27 @@ public function add_dependency(base_setting $dependentsetting, $type=null, $opti
$dependency->get_dependent_setting()->register_dependent_dependency($dependency);
}
+ /**
+ * Get the PARAM_XXXX validation to be applied to the setting
+ *
+ * @return string The PARAM_XXXX constant of null if the setting type is not defined
+ */
+ public function get_param_validation() {
+ switch ($this->vtype) {
+ case self::IS_BOOLEAN:
+ return PARAM_BOOL;
+ case self::IS_INTEGER:
+ return PARAM_INT;
+ case self::IS_FILENAME:
+ return PARAM_FILE;
+ case self::IS_PATH:
+ return PARAM_PATH;
+ case self::IS_TEXT:
+ return PARAM_TEXT;
+ }
+ return null;
+ }
+
// Protected API starts here
protected function validate_value($vtype, $value) {
@@ -124,6 +124,16 @@ public function get_value() {
public function get_static_value() {
return $this->setting->get_value();
}
+
+ /**
+ * Gets the the PARAM_XXXX validation to be applied to the setting
+ *
+ * return string The PARAM_XXXX constant of null if the setting type is not defined
+ */
+ public function get_param_validation() {
+ return $this->setting->get_param_validation();
+ }
+
/**
* Sets the label
* @param string $label
@@ -83,11 +83,21 @@ function definition() {
$mform = $this->_form;
$mform->setDisableShortforms();
$stage = $mform->addElement('hidden', 'stage', $this->uistage->get_stage());
+ $mform->setType('stage', PARAM_INT);
$stage = $mform->addElement('hidden', $ui->get_name(), $ui->get_uniqueid());
+ $mform->setType($ui->get_name(), PARAM_ALPHANUM);
$params = $this->uistage->get_params();
if (is_array($params) && count($params) > 0) {
foreach ($params as $name=>$value) {
+ // TODO: Horrible hack, but current backup ui structure does not allow
+ // to make this easy (only changing params to objects that would be
+ // possible. MDL-38735.
+ $intparams = array(
+ 'contextid', 'importid', 'target');
$stage = $mform->addElement('hidden', $name, $value);
+ if (in_array($name, $intparams)) {
+ $mform->setType($name, PARAM_INT);
+ }
}
}
}
@@ -156,6 +166,7 @@ public function add_settings(array $settingstasks) {
// Then call the add method with the get_element_properties array
call_user_func_array(array($this->_form, 'addElement'), $setting->get_ui()->get_element_properties($task, $OUTPUT));
+ $this->_form->setType($setting->get_ui_name(), $setting->get_param_validation());
$defaults[$setting->get_ui_name()] = $setting->get_value();
if ($setting->has_help()) {
list($identifier, $component) = $setting->get_help();
@@ -262,6 +273,7 @@ function add_fixed_setting(backup_setting $setting, base_task $task) {
$this->_form->addElement('html', html_writer::end_tag('div'));
}
$this->_form->addElement('hidden', $settingui->get_name(), $settingui->get_value());
+ $this->_form->setType($settingui->get_name(), $settingui->get_param_validation());
}
/**
* Adds dependencies to the form recursively

0 comments on commit 5ae69b2

Please sign in to comment.