MDL-38735 backup: add missing setType() to forms
This commit is contained in:
@@ -28,6 +28,7 @@ class course_restore_form extends moodleform {
|
||||
$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 @@ abstract class base_setting {
|
||||
$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 @@ class base_setting_ui {
|
||||
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 @@ abstract class base_moodleform extends moodleform {
|
||||
$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 @@ abstract class base_moodleform extends moodleform {
|
||||
|
||||
// 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 @@ abstract class base_moodleform extends moodleform {
|
||||
$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
|
||||
|
||||
Reference in New Issue
Block a user