mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
backup MDL-23559 Moved UI validation routines from backup_setting to backup_setting_ui and fixed label validation problems
This commit is contained in:
parent
39bca973c1
commit
86e0afcfaa
@ -65,8 +65,6 @@ abstract class backup_setting extends base_setting implements checksumable {
|
||||
* @param array $options
|
||||
*/
|
||||
public function make_ui($type, $label, array $attributes = null, array $options = null) {
|
||||
$type = $this->validate_ui_type($type);
|
||||
$label = $this->validate_ui_label($label);
|
||||
$this->uisetting = backup_setting_ui::make($this, $type, $label, $attributes, $options);
|
||||
if (is_array($options) || is_object($options)) {
|
||||
$options = (array)$options;
|
||||
|
@ -435,21 +435,6 @@ abstract class base_setting {
|
||||
return $status;
|
||||
}
|
||||
|
||||
protected function validate_ui_type($type) {
|
||||
if ($type !== self::UI_HTML_CHECKBOX && $type !== self::UI_HTML_RADIOBUTTON &&
|
||||
$type !== self::UI_HTML_DROPDOWN && $type !== self::UI_HTML_TEXTFIELD) {
|
||||
throw new base_setting_exception('setting_invalid_ui_type');
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
|
||||
protected function validate_ui_label($label) {
|
||||
if (empty($label) || $label !== clean_param($label, PARAM_TEXT)) {
|
||||
throw new base_setting_exception('setting_invalid_ui_label');
|
||||
}
|
||||
return $label;
|
||||
}
|
||||
|
||||
protected function inform_dependencies($ctype, $oldv) {
|
||||
foreach ($this->dependencies as $dependency) {
|
||||
$dependency->process_change($ctype, $oldv);
|
||||
|
@ -115,6 +115,9 @@ class base_setting_ui {
|
||||
* @param string $label
|
||||
*/
|
||||
public function set_label($label) {
|
||||
if (empty($label) || $label !== clean_param($label, PARAM_TEXT)) {
|
||||
throw new base_setting_ui_exception('setting_invalid_ui_label');
|
||||
}
|
||||
$this->label = $label;
|
||||
}
|
||||
/**
|
||||
@ -174,12 +177,15 @@ abstract class backup_setting_ui extends base_setting_ui {
|
||||
/**
|
||||
* Creates a new backup setting ui based on the setting it is given
|
||||
*
|
||||
* Throws an exception if an invalid type is provided.
|
||||
*
|
||||
* @param backup_setting $setting
|
||||
* @param int $type The backup_setting UI type. One of backup_setting::UI_*;
|
||||
* @param string $label The label to display with the setting ui
|
||||
* @param array $attributes Array of HTML attributes to apply to the element
|
||||
* @param array $options Array of options to apply to the setting ui object
|
||||
* @return backup_setting_ui_text
|
||||
*
|
||||
* @return backup_setting_ui_text|backup_setting_ui_checkbox|backup_setting_ui_select|backup_setting_ui_radio
|
||||
*/
|
||||
final public static function make(backup_setting $setting, $type, $label, array $attributes = null, array $options=null) {
|
||||
// Base the decision we make on the type that was sent
|
||||
@ -193,7 +199,7 @@ abstract class backup_setting_ui extends base_setting_ui {
|
||||
case backup_setting::UI_HTML_TEXTFIELD :
|
||||
return new backup_setting_ui_text($setting, $label, $attributes, $options);
|
||||
default:
|
||||
return false;
|
||||
throw new backup_setting_ui_exception('setting_invalid_ui_type');
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -520,4 +526,7 @@ class backup_setting_ui_dateselector extends backup_setting_ui_text {
|
||||
}
|
||||
return parent::get_static_value();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class base_setting_ui_exception extends base_setting_exception {}
|
||||
class backup_setting_ui_exception extends base_setting_ui_exception {};
|
Loading…
x
Reference in New Issue
Block a user