Skip to content

Commit

Permalink
MDL-44912 libraries: Allow empty values in admin setting colour picker
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Apr 2, 2014
1 parent c790670 commit 907a673
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 13 additions & 2 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -8142,6 +8142,11 @@ class admin_setting_configcolourpicker extends admin_setting {
*/
protected $previewconfig = null;

/**
* Use default when empty.
*/
protected $usedefaultwhenempty = true;

/**
*
* @param string $name
Expand All @@ -8150,8 +8155,10 @@ class admin_setting_configcolourpicker extends admin_setting {
* @param string $defaultsetting
* @param array $previewconfig Array('selector'=>'.some .css .selector','style'=>'backgroundColor');
*/
public function __construct($name, $visiblename, $description, $defaultsetting, array $previewconfig=null) {
public function __construct($name, $visiblename, $description, $defaultsetting, array $previewconfig = null,
$usedefaultwhenempty = true) {
$this->previewconfig = $previewconfig;
$this->usedefaultwhenempty = $usedefaultwhenempty;
parent::__construct($name, $visiblename, $description, $defaultsetting);
}

Expand Down Expand Up @@ -8242,7 +8249,11 @@ protected function validate($data) {
} else if (($data == 'transparent') || ($data == 'currentColor') || ($data == 'inherit')) {
return $data;
} else if (empty($data)) {
return $this->defaultsetting;
if ($this->usedefaultwhenempty){
return $this->defaultsetting;
} else {
return '';
}
} else {
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions theme/more/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$title = get_string('textcolor', 'theme_more');
$description = get_string('textcolor_desc', 'theme_more');
$default = '#333366';
$setting = new admin_setting_configcolourpicker($name, $title, $description, $default);
$setting = new admin_setting_configcolourpicker($name, $title, $description, $default, null, false);
$setting->set_updatedcallback('theme_reset_all_caches');
$settings->add($setting);

Expand All @@ -49,7 +49,7 @@
$title = get_string('linkcolor', 'theme_more');
$description = get_string('linkcolor_desc', 'theme_more');
$default = '#FF6500';
$setting = new admin_setting_configcolourpicker($name, $title, $description, $default);
$setting = new admin_setting_configcolourpicker($name, $title, $description, $default, null, false);
$setting->set_updatedcallback('theme_reset_all_caches');
$settings->add($setting);

Expand All @@ -58,7 +58,7 @@
$title = get_string('bodybackground', 'theme_more');
$description = get_string('bodybackground_desc', 'theme_more');
$default = '';
$setting = new admin_setting_configcolourpicker($name, $title, $description, $default);
$setting = new admin_setting_configcolourpicker($name, $title, $description, $default, null, false);
$setting->set_updatedcallback('theme_reset_all_caches');
$settings->add($setting);

Expand Down Expand Up @@ -120,7 +120,7 @@
$title = get_string('contentbackground', 'theme_more');
$description = get_string('contentbackground_desc', 'theme_more');
$default = '#FFFFFF';
$setting = new admin_setting_configcolourpicker($name, $title, $description, $default);
$setting = new admin_setting_configcolourpicker($name, $title, $description, $default, null, false);
$setting->set_updatedcallback('theme_reset_all_caches');
$settings->add($setting);

Expand All @@ -129,7 +129,7 @@
$title = get_string('secondarybackground', 'theme_more');
$description = get_string('secondarybackground_desc', 'theme_more');
$default = '#FFFFFF';
$setting = new admin_setting_configcolourpicker($name, $title, $description, $default);
$setting = new admin_setting_configcolourpicker($name, $title, $description, $default, null, false);
$setting->set_updatedcallback('theme_reset_all_caches');
$settings->add($setting);

Expand Down

0 comments on commit 907a673

Please sign in to comment.