diff --git a/backup/restorefile_form.php b/backup/restorefile_form.php index f83ee22e78db2..f903415745b13 100644 --- a/backup/restorefile_form.php +++ b/backup/restorefile_form.php @@ -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); diff --git a/backup/util/settings/base_setting.class.php b/backup/util/settings/base_setting.class.php index 765c6ac1aab77..c5cb56754d46c 100644 --- a/backup/util/settings/base_setting.class.php +++ b/backup/util/settings/base_setting.class.php @@ -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) { diff --git a/backup/util/ui/backup_ui_setting.class.php b/backup/util/ui/backup_ui_setting.class.php index e660c4a4c0bf5..9ef58656a2488 100644 --- a/backup/util/ui/backup_ui_setting.class.php +++ b/backup/util/ui/backup_ui_setting.class.php @@ -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 diff --git a/backup/util/ui/base_moodleform.class.php b/backup/util/ui/base_moodleform.class.php index 7a733ee9e8d73..f0604a5ab6099 100644 --- a/backup/util/ui/base_moodleform.class.php +++ b/backup/util/ui/base_moodleform.class.php @@ -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