Skip to content

Commit

Permalink
Merge branch 'MDL-38735' of git://github.com/stronk7/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Apr 3, 2013
2 parents 89cc981 + 5ae69b2 commit 0bcdbb7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions backup/restorefile_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions backup/util/settings/base_setting.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions backup/util/ui/backup_ui_setting.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions backup/util/ui/base_moodleform.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0bcdbb7

Please sign in to comment.