mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 18:06:51 +02:00
Merge branch 'MDL-49423-master' of git://github.com/jleyva/moodle
This commit is contained in:
commit
0db24a200a
12 changed files with 382 additions and 5 deletions
|
@ -2946,6 +2946,8 @@ class admin_setting_configmulticheckbox2 extends admin_setting_configmulticheckb
|
|||
class admin_setting_configselect extends admin_setting {
|
||||
/** @var array Array of choices value=>label */
|
||||
public $choices;
|
||||
/** @var array Array of choices grouped using optgroups */
|
||||
public $optgroups;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -2956,7 +2958,18 @@ class admin_setting_configselect extends admin_setting {
|
|||
* @param array $choices array of $value=>$label for each selection
|
||||
*/
|
||||
public function __construct($name, $visiblename, $description, $defaultsetting, $choices) {
|
||||
$this->choices = $choices;
|
||||
// Look for optgroup and single options.
|
||||
if (is_array($choices)) {
|
||||
foreach ($choices as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
$this->optgroups[$key] = $val;
|
||||
$this->choices = array_merge($this->choices, $val);
|
||||
} else {
|
||||
$this->choices[$key] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct($name, $visiblename, $description, $defaultsetting);
|
||||
}
|
||||
|
||||
|
@ -3089,6 +3102,27 @@ class admin_setting_configselect extends admin_setting {
|
|||
}
|
||||
|
||||
$options = [];
|
||||
$template = 'core_admin/setting_configselect';
|
||||
|
||||
if (!empty($this->optgroups)) {
|
||||
$optgroups = [];
|
||||
foreach ($this->optgroups as $label => $choices) {
|
||||
$optgroup = array('label' => $label, 'options' => []);
|
||||
foreach ($choices as $value => $name) {
|
||||
$optgroup['options'][] = [
|
||||
'value' => $value,
|
||||
'name' => $name,
|
||||
'selected' => (string) $value == $data
|
||||
];
|
||||
unset($this->choices[$value]);
|
||||
}
|
||||
$optgroups[] = $optgroup;
|
||||
}
|
||||
$context->options = $options;
|
||||
$context->optgroups = $optgroups;
|
||||
$template = 'core_admin/setting_configselect_optgroup';
|
||||
}
|
||||
|
||||
foreach ($this->choices as $value => $name) {
|
||||
$options[] = [
|
||||
'value' => $value,
|
||||
|
@ -3098,7 +3132,7 @@ class admin_setting_configselect extends admin_setting {
|
|||
}
|
||||
$context->options = $options;
|
||||
|
||||
$element = $OUTPUT->render_from_template('core_admin/setting_configselect', $context);
|
||||
$element = $OUTPUT->render_from_template($template, $context);
|
||||
|
||||
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, $warning, $defaultinfo, $query);
|
||||
}
|
||||
|
@ -3221,6 +3255,29 @@ class admin_setting_configmultiselect extends admin_setting_configselect {
|
|||
|
||||
$defaults = [];
|
||||
$options = [];
|
||||
$template = 'core_admin/setting_configmultiselect';
|
||||
|
||||
if (!empty($this->optgroups)) {
|
||||
$optgroups = [];
|
||||
foreach ($this->optgroups as $label => $choices) {
|
||||
$optgroup = array('label' => $label, 'options' => []);
|
||||
foreach ($choices as $value => $name) {
|
||||
if (in_array($value, $default)) {
|
||||
$defaults[] = $name;
|
||||
}
|
||||
$optgroup['options'][] = [
|
||||
'value' => $value,
|
||||
'name' => $name,
|
||||
'selected' => in_array($value, $data)
|
||||
];
|
||||
unset($this->choices[$value]);
|
||||
}
|
||||
$optgroups[] = $optgroup;
|
||||
}
|
||||
$context->optgroups = $optgroups;
|
||||
$template = 'core_admin/setting_configmultiselect_optgroup';
|
||||
}
|
||||
|
||||
foreach ($this->choices as $value => $name) {
|
||||
if (in_array($value, $default)) {
|
||||
$defaults[] = $name;
|
||||
|
@ -3241,7 +3298,7 @@ class admin_setting_configmultiselect extends admin_setting_configselect {
|
|||
$defaultinfo = get_string('none');
|
||||
}
|
||||
|
||||
$element = $OUTPUT->render_from_template('core_admin/setting_configmultiselect', $context);
|
||||
$element = $OUTPUT->render_from_template($template, $context);
|
||||
|
||||
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue