* @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;
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);
* @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;
}
/**
/**
* 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
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');
}
}
/**
}
return parent::get_static_value();
}
-}
\ No newline at end of file
+}
+
+class base_setting_ui_exception extends base_setting_exception {}
+class backup_setting_ui_exception extends base_setting_ui_exception {};
\ No newline at end of file