MDL-49423 admin: Support optgroup in admin_setting_configmultiselect

This commit is contained in:
Juan Leyva 2016-12-30 14:00:40 +01:00
parent 25905de518
commit 1295885084
4 changed files with 133 additions and 3 deletions

View file

@ -3255,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;
@ -3275,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);
}