mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
MDL-49423 admin: Support optgroup in admin_setting_configmultiselect
This commit is contained in:
parent
25905de518
commit
1295885084
4 changed files with 133 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue