From df7602298a0198b6eff37fbe5588b8a69d216315 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Mon, 15 Aug 2016 17:38:24 +0800 Subject: [PATCH] MDL-55564 core_admin: Convert admin settings to use templates Part of MDL-55071 --- admin/settings.php | 65 +- admin/templates/setting.mustache | 43 + .../templates/setting_configcheckbox.mustache | 23 + .../setting_configcolourpicker.mustache | 30 + .../setting_configdirectory.mustache | 20 + .../templates/setting_configduration.mustache | 29 + admin/templates/setting_configempty.mustache | 22 + .../setting_configexecutable.mustache | 20 + admin/templates/setting_configfile.mustache | 31 + .../setting_confightmleditor.mustache | 20 + .../setting_configmulticheckbox.mustache | 32 + .../setting_configmultiselect.mustache | 28 + .../setting_configpasswordunmask.mustache | 57 ++ admin/templates/setting_configselect.mustache | 27 + admin/templates/setting_configtext.mustache | 22 + .../templates/setting_configtextarea.mustache | 22 + admin/templates/setting_configtime.mustache | 34 + .../setting_courselist_frontpage.mustache | 29 + .../setting_devicedetectregex.mustache | 39 + admin/templates/setting_emoticons.mustache | 51 ++ admin/templates/setting_flag.mustache | 21 + .../templates/setting_gradecat_combo.mustache | 31 + admin/templates/setting_heading.mustache | 25 + .../setting_special_calendar_weekend.mustache | 40 + admin/templates/settings.mustache | 38 + lib/adminlib.php | 853 +++++++++--------- 26 files changed, 1170 insertions(+), 482 deletions(-) create mode 100644 admin/templates/setting.mustache create mode 100644 admin/templates/setting_configcheckbox.mustache create mode 100644 admin/templates/setting_configcolourpicker.mustache create mode 100644 admin/templates/setting_configdirectory.mustache create mode 100644 admin/templates/setting_configduration.mustache create mode 100644 admin/templates/setting_configempty.mustache create mode 100644 admin/templates/setting_configexecutable.mustache create mode 100644 admin/templates/setting_configfile.mustache create mode 100644 admin/templates/setting_confightmleditor.mustache create mode 100644 admin/templates/setting_configmulticheckbox.mustache create mode 100644 admin/templates/setting_configmultiselect.mustache create mode 100644 admin/templates/setting_configpasswordunmask.mustache create mode 100644 admin/templates/setting_configselect.mustache create mode 100644 admin/templates/setting_configtext.mustache create mode 100644 admin/templates/setting_configtextarea.mustache create mode 100644 admin/templates/setting_configtime.mustache create mode 100644 admin/templates/setting_courselist_frontpage.mustache create mode 100644 admin/templates/setting_devicedetectregex.mustache create mode 100644 admin/templates/setting_emoticons.mustache create mode 100644 admin/templates/setting_flag.mustache create mode 100644 admin/templates/setting_gradecat_combo.mustache create mode 100644 admin/templates/setting_heading.mustache create mode 100644 admin/templates/setting_special_calendar_weekend.mustache create mode 100644 admin/templates/settings.mustache diff --git a/admin/settings.php b/admin/settings.php index fda235959b2b4..72f7f9cbe2a98 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -77,20 +77,23 @@ // --------------------------------------------------------------------------------------------------------------- - echo '
'; - echo '
'; - echo html_writer::input_hidden_params($PAGE->url); - echo ''; - echo ''; - // HACK to prevent browsers from automatically inserting the user's password into the wrong fields. - echo prevent_form_autofill_password(); - - echo $settingspage->output_html(); - - echo '
'; - - echo '
'; - echo '
'; + $pageparams = $PAGE->url->params(); + $context = [ + 'actionurl' => $PAGE->url->out(false), + 'params' => array_map(function($param) use ($pageparams) { + return [ + 'name' => $param, + 'value' => $pageparams[$param] + ]; + }, array_keys($pageparams)), + 'sesskey' => sesskey(), + 'return' => $return, + 'title' => null, + 'settings' => $settingspage->output_html(), + 'showsave' => true + ]; + + echo $OUTPUT->render_from_template('core_admin/settings', $context); } else { if ($PAGE->user_allowed_editing()) { @@ -121,23 +124,23 @@ // --------------------------------------------------------------------------------------------------------------- - echo '
'; - echo '
'; - echo html_writer::input_hidden_params($PAGE->url); - echo ''; - echo ''; - // HACK to prevent browsers from automatically inserting the user's password into the wrong fields. - echo prevent_form_autofill_password(); - echo $OUTPUT->heading($settingspage->visiblename); - - echo $settingspage->output_html(); - - if ($settingspage->show_save()) { - echo '
'; - } - - echo '
'; - echo '
'; + $pageparams = $PAGE->url->params(); + $context = [ + 'actionurl' => $PAGE->url->out(false), + 'params' => array_map(function($param) use ($pageparams) { + return [ + 'name' => $param, + 'value' => $pageparams[$param] + ]; + }, array_keys($pageparams)), + 'sesskey' => sesskey(), + 'return' => $return, + 'title' => $settingspage->visiblename, + 'settings' => $settingspage->output_html(), + 'showsave' => $settingspage->show_save() + ]; + + echo $OUTPUT->render_from_template('core_admin/settings', $context); } $PAGE->requires->yui_module('moodle-core-formchangechecker', diff --git a/admin/templates/setting.mustache b/admin/templates/setting.mustache new file mode 100644 index 0000000000000..33e760d7f1d78 --- /dev/null +++ b/admin/templates/setting.mustache @@ -0,0 +1,43 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting. +}} +
+
+ + {{{name}}} +
+
+ {{#error}} +
{{error}}
+ {{/error}} + {{{element}}} + {{#default}} +
{{{default}}}
+ {{/default}} +
+
{{{description}}}
+
diff --git a/admin/templates/setting_configcheckbox.mustache b/admin/templates/setting_configcheckbox.mustache new file mode 100644 index 0000000000000..6d363ed7322e7 --- /dev/null +++ b/admin/templates/setting_configcheckbox.mustache @@ -0,0 +1,23 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting configdirectory. +}} +
+ + +
diff --git a/admin/templates/setting_configcolourpicker.mustache b/admin/templates/setting_configcolourpicker.mustache new file mode 100644 index 0000000000000..0ad6ec6599788 --- /dev/null +++ b/admin/templates/setting_configcolourpicker.mustache @@ -0,0 +1,30 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting configcolourpicker. +}} +
+
+ {{#icon}} + {{>core/pix_icon}} + {{/icon}} +
+ + {{#haspreviewconfig}} + + {{/haspreviewconfig}} +
diff --git a/admin/templates/setting_configdirectory.mustache b/admin/templates/setting_configdirectory.mustache new file mode 100644 index 0000000000000..5ea2cd7374b63 --- /dev/null +++ b/admin/templates/setting_configdirectory.mustache @@ -0,0 +1,20 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting configdirectory. +}} +{{>core_admin/setting_configfile}} diff --git a/admin/templates/setting_configduration.mustache b/admin/templates/setting_configduration.mustache new file mode 100644 index 0000000000000..1d7f3e79013b3 --- /dev/null +++ b/admin/templates/setting_configduration.mustache @@ -0,0 +1,29 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting configduration. +}} +
+ + + +
+ diff --git a/admin/templates/setting_configempty.mustache b/admin/templates/setting_configempty.mustache new file mode 100644 index 0000000000000..ec391e9cc9ca5 --- /dev/null +++ b/admin/templates/setting_configempty.mustache @@ -0,0 +1,22 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting configempty. +}} +
+ +
diff --git a/admin/templates/setting_configexecutable.mustache b/admin/templates/setting_configexecutable.mustache new file mode 100644 index 0000000000000..c93134a879fd0 --- /dev/null +++ b/admin/templates/setting_configexecutable.mustache @@ -0,0 +1,20 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting configexecutable. +}} +{{>core_admin/setting_configfile}} diff --git a/admin/templates/setting_configfile.mustache b/admin/templates/setting_configfile.mustache new file mode 100644 index 0000000000000..e2bb3b76d5295 --- /dev/null +++ b/admin/templates/setting_configfile.mustache @@ -0,0 +1,31 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting configfile. +}} +
+ + {{#showvalidity}} + {{#valid}} + + {{/valid}} + {{^valid}} + + {{/valid}} + {{/showvalidity}} +
+ diff --git a/admin/templates/setting_confightmleditor.mustache b/admin/templates/setting_confightmleditor.mustache new file mode 100644 index 0000000000000..dbfd3fa48bc0d --- /dev/null +++ b/admin/templates/setting_confightmleditor.mustache @@ -0,0 +1,20 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting confightmleditor. +}} +{{>core_admin/setting_configtextarea}} diff --git a/admin/templates/setting_configmulticheckbox.mustache b/admin/templates/setting_configmulticheckbox.mustache new file mode 100644 index 0000000000000..ed31eeaee5ec9 --- /dev/null +++ b/admin/templates/setting_configmulticheckbox.mustache @@ -0,0 +1,32 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting configmulticheckbox. +}} +
+ + {{#hasoptions}} +
    + {{#options}} +
  • + + +
  • + {{/options}} +
+ {{/hasoptions}} +
diff --git a/admin/templates/setting_configmultiselect.mustache b/admin/templates/setting_configmultiselect.mustache new file mode 100644 index 0000000000000..88baa846d6490 --- /dev/null +++ b/admin/templates/setting_configmultiselect.mustache @@ -0,0 +1,28 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting configmultiselect. +}} +
+ + +
+ diff --git a/admin/templates/setting_configpasswordunmask.mustache b/admin/templates/setting_configpasswordunmask.mustache new file mode 100644 index 0000000000000..dd5c0becc5241 --- /dev/null +++ b/admin/templates/setting_configpasswordunmask.mustache @@ -0,0 +1,57 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting configpasswordunmask. +}} +
+ +
+
+{{#js}} +(function() { + var id = '{{id}}'; + var unmaskid = id + 'unmask'; + var unmaskdivid = id + 'unmaskdiv'; + var unmaskstr = {{#quote}}{{#str}}unmaskpassword, form{{/str}}{{/quote}}; + var is_ie = (navigator.userAgent.toLowerCase().indexOf("msie") != -1); + + document.getElementById(id).setAttribute("autocomplete", "off"); + + var unmaskdiv = document.getElementById(unmaskdivid); + + var unmaskchb = document.createElement("input"); + unmaskchb.setAttribute("type", "checkbox"); + unmaskchb.setAttribute("id", unmaskid); + unmaskchb.onchange = function() {unmaskPassword(id);}; + unmaskdiv.appendChild(unmaskchb); + + var unmasklbl = document.createElement("label"); + unmasklbl.innerHTML = unmaskstr; + if (is_ie) { + unmasklbl.setAttribute("htmlFor", unmaskid); + } else { + unmasklbl.setAttribute("for", unmaskid); + } + unmaskdiv.appendChild(unmasklbl); + + if (is_ie) { + // Ugly hack to work around the famous onchange IE bug. + unmaskchb.onclick = function() {this.blur();}; + unmaskdiv.onclick = function() {this.blur();}; + } +})() +{{/js}} diff --git a/admin/templates/setting_configselect.mustache b/admin/templates/setting_configselect.mustache new file mode 100644 index 0000000000000..199f5291adfcd --- /dev/null +++ b/admin/templates/setting_configselect.mustache @@ -0,0 +1,27 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting configselect. +}} +
+ +
+ diff --git a/admin/templates/setting_configtext.mustache b/admin/templates/setting_configtext.mustache new file mode 100644 index 0000000000000..3d99fc379127e --- /dev/null +++ b/admin/templates/setting_configtext.mustache @@ -0,0 +1,22 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting configtext. +}} +
+ +
diff --git a/admin/templates/setting_configtextarea.mustache b/admin/templates/setting_configtextarea.mustache new file mode 100644 index 0000000000000..5c620554ccfaf --- /dev/null +++ b/admin/templates/setting_configtextarea.mustache @@ -0,0 +1,22 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting configtextarea. +}} +
+ +
diff --git a/admin/templates/setting_configtime.mustache b/admin/templates/setting_configtime.mustache new file mode 100644 index 0000000000000..a17aefbfe422e --- /dev/null +++ b/admin/templates/setting_configtime.mustache @@ -0,0 +1,34 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting configtime. +}} +
+ + : + + +
+ diff --git a/admin/templates/setting_courselist_frontpage.mustache b/admin/templates/setting_courselist_frontpage.mustache new file mode 100644 index 0000000000000..d50192401b459 --- /dev/null +++ b/admin/templates/setting_courselist_frontpage.mustache @@ -0,0 +1,29 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting courselist_frontpage. +}} +
+ {{#selects}} + +
+ {{/selects}} +
diff --git a/admin/templates/setting_devicedetectregex.mustache b/admin/templates/setting_devicedetectregex.mustache new file mode 100644 index 0000000000000..1cdeb8e5965c8 --- /dev/null +++ b/admin/templates/setting_devicedetectregex.mustache @@ -0,0 +1,39 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting devicedetectregex. +}} + + + + + + + + + {{#expressions}} + + + + + {{/expressions}} + +
{{#str}}devicedetectregexexpression, admin{{/str}}{{#str}}devicedetectregexvalue, admin{{/str}}
+ + + +
diff --git a/admin/templates/setting_emoticons.mustache b/admin/templates/setting_emoticons.mustache new file mode 100644 index 0000000000000..cdd7a1b61739b --- /dev/null +++ b/admin/templates/setting_emoticons.mustache @@ -0,0 +1,51 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting emoticons. +}} +
+ + + + + + + + + + + + {{#emoticons}} + + {{#fields}} + + {{/fields}} + + + {{/emoticons}} + +
{{#str}}emoticontext, admin{{/str}}{{#str}}emoticonimagename, admin{{/str}}{{#str}}emoticoncomponent, admin{{/str}}{{#str}}emoticonalt, admin{{/str}}
+ + + {{#icon}} + {{>core/pix_icon}} + {{/icon}} +
+
+ diff --git a/admin/templates/setting_flag.mustache b/admin/templates/setting_flag.mustache new file mode 100644 index 0000000000000..85ad557f08fb2 --- /dev/null +++ b/admin/templates/setting_flag.mustache @@ -0,0 +1,21 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting flag. +}} + + \ No newline at end of file diff --git a/admin/templates/setting_gradecat_combo.mustache b/admin/templates/setting_gradecat_combo.mustache new file mode 100644 index 0000000000000..1016373f1c87d --- /dev/null +++ b/admin/templates/setting_gradecat_combo.mustache @@ -0,0 +1,31 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting gradecat_combo. +}} +
+ + + + + +
+ diff --git a/admin/templates/setting_heading.mustache b/admin/templates/setting_heading.mustache new file mode 100644 index 0000000000000..05b1f21f616dc --- /dev/null +++ b/admin/templates/setting_heading.mustache @@ -0,0 +1,25 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting heading. +}} +{{#title}} +

{{title}}

+{{/title}} +{{#description}} +
{{{descriptionformatted}}}
+{{/description}} diff --git a/admin/templates/setting_special_calendar_weekend.mustache b/admin/templates/setting_special_calendar_weekend.mustache new file mode 100644 index 0000000000000..10259e0fc95f1 --- /dev/null +++ b/admin/templates/setting_special_calendar_weekend.mustache @@ -0,0 +1,40 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Setting special_calendar_weekend. +}} + + + + + {{#days}} + + {{/days}} + + + + + {{#days}} + + {{/days}} + + +
+ +
+ +
diff --git a/admin/templates/settings.mustache b/admin/templates/settings.mustache new file mode 100644 index 0000000000000..30be66142b8cb --- /dev/null +++ b/admin/templates/settings.mustache @@ -0,0 +1,38 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + Settings. +}} +
+
+ {{#params}} + + {{/params}} + + + {{>core/prevent_form_autofill_password}} + {{#title}} +

{{title}}

+ {{/title}} + {{{settings}}} + {{#showsave}} +
+ +
+ {{/showsave}} +
+
diff --git a/lib/adminlib.php b/lib/adminlib.php index af6015fb96734..1938e70733e5f 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -2017,15 +2017,18 @@ public function write_setting_flag(admin_setting $setting, $data) { * @return string - The html for the checkbox. */ public function output_setting_flag(admin_setting $setting) { + global $OUTPUT; + $value = $setting->get_setting_flag_value($this); - $output = ' ' . - ' '; - return $output; + + $context = new stdClass(); + $context->id = $setting->get_id() . '_' . $this->get_shortname(); + $context->name = $setting->get_full_name() . '_' . $this->get_shortname(); + $context->value = 1; + $context->checked = $value ? true : false; + $context->label = $this->get_displayname(); + + return $OUTPUT->render_from_template('core_admin/setting_flag', $context); } } @@ -2079,14 +2082,11 @@ public function write_setting($data) { */ public function output_html($data, $query='') { global $OUTPUT; - $return = ''; - if ($this->visiblename != '') { - $return .= $OUTPUT->heading($this->visiblename, 3, 'main'); - } - if ($this->description != '') { - $return .= $OUTPUT->box(highlight($query, markdown_to_html($this->description)), 'generalbox formsettingheading'); - } - return $return; + $context = new stdClass(); + $context->title = $this->visiblename; + $context->description = $this->description; + $context->descriptionformatted = highlight($query, markdown_to_html($this->description)); + return $OUTPUT->render_from_template('core_admin/setting_heading', $context); } } @@ -2177,11 +2177,18 @@ public function validate($data) { * @return string Returns an XHTML string */ public function output_html($data, $query='') { + global $OUTPUT; + $default = $this->get_defaultsetting(); + $context = (object) [ + 'size' => $this->size, + 'id' => $this->get_id(), + 'name' => $this->get_full_name(), + 'value' => $data + ]; + $element = $OUTPUT->render_from_template('core_admin/setting_configtext', $context); - return format_admin_setting($this, $this->visiblename, - '
', - $this->description, true, '', $default, $query); + return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $default, $query); } } @@ -2271,16 +2278,24 @@ public function __construct($name, $visiblename, $description, $defaultsetting, * @return string XHTML string for the editor */ public function output_html($data, $query='') { - $default = $this->get_defaultsetting(); + global $OUTPUT; + $default = $this->get_defaultsetting(); $defaultinfo = $default; if (!is_null($default) and $default !== '') { $defaultinfo = "\n".$default; } - return format_admin_setting($this, $this->visiblename, - '
', - $this->description, true, '', $defaultinfo, $query); + $context = (object) [ + 'cols' => $this->cols, + 'rows' => $this->rows, + 'id' => $this->get_id(), + 'name' => $this->get_full_name(), + 'value' => $data + ]; + $element = $OUTPUT->render_from_template('core_admin/setting_configtextarea', $context); + + return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query); } } @@ -2288,9 +2303,7 @@ public function output_html($data, $query='') { /** * General text area with html editor. */ -class admin_setting_confightmleditor extends admin_setting_configtext { - private $rows; - private $cols; +class admin_setting_confightmleditor extends admin_setting_configtextarea { /** * @param string $name @@ -2300,9 +2313,7 @@ class admin_setting_confightmleditor extends admin_setting_configtext { * @param mixed $paramtype */ public function __construct($name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW, $cols='60', $rows='8') { - $this->rows = $rows; - $this->cols = $cols; - parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype); + parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype, $cols, $rows); editors_head_setup(); } @@ -2314,20 +2325,10 @@ public function __construct($name, $visiblename, $description, $defaultsetting, * @return string XHTML string for the editor */ public function output_html($data, $query='') { - $default = $this->get_defaultsetting(); - - $defaultinfo = $default; - if (!is_null($default) and $default !== '') { - $defaultinfo = "\n".$default; - } - $editor = editors_get_preferred_editor(FORMAT_HTML); $editor->set_text($data); $editor->use_editor($this->get_id(), array('noclean'=>true)); - - return format_admin_setting($this, $this->visiblename, - '
', - $this->description, true, '', $defaultinfo, $query); + return parent::output_html($data, $query); } } @@ -2375,41 +2376,15 @@ protected function add_to_config_log($name, $oldvalue, $value) { * @return string XHTML field */ public function output_html($data, $query='') { - $id = $this->get_id(); - $unmask = get_string('unmaskpassword', 'form'); - $unmaskjs = ''; - return format_admin_setting($this, $this->visiblename, - '
'.$unmaskjs.'
', - $this->description, true, '', NULL, $query); + global $OUTPUT; + $context = (object) [ + 'id' => $this->get_id(), + 'name' => $this->get_full_name(), + 'size' => $this->size, + 'value' => $data + ]; + $element = $OUTPUT->render_from_template('core_admin/setting_configpasswordunmask', $context); + return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', null, $query); } } @@ -2438,18 +2413,15 @@ public function __construct($name, $visiblename, $description) { * @return string XHTML string for the editor */ public function output_html($data, $query='') { - return format_admin_setting($this, - $this->visiblename, - '
' . - '
', - $this->description, - true, - '', - get_string('none'), - $query); + global $OUTPUT; + + $context = (object) [ + 'id' => $this->get_id(), + 'name' => $this->get_full_name() + ]; + $element = $OUTPUT->render_from_template('core_admin/setting_configempty', $context); + + return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', get_string('none'), $query); } } @@ -2482,27 +2454,26 @@ public function __construct($name, $visiblename, $description, $defaultdirectory * @return string XHTML field */ public function output_html($data, $query='') { - global $CFG; + global $CFG, $OUTPUT; + $default = $this->get_defaultsetting(); + $context = (object) [ + 'id' => $this->get_id(), + 'name' => $this->get_full_name(), + 'size' => $this->size, + 'value' => $data, + 'showvalidity' => !empty($data), + 'valid' => $data && file_exists($data), + 'readonly' => !empty($CFG->preventexecpath) + ]; - if ($data) { - if (file_exists($data)) { - $executable = ''; - } else { - $executable = ''; - } - } else { - $executable = ''; - } - $readonly = ''; - if (!empty($CFG->preventexecpath)) { + if ($context->readonly) { $this->visiblename .= '
'.get_string('execpathnotallowed', 'admin').'
'; - $readonly = 'readonly="readonly"'; } - return format_admin_setting($this, $this->visiblename, - '
'.$executable.'
', - $this->description, true, '', $default, $query); + $element = $OUTPUT->render_from_template('core_admin/setting_configfile', $context); + + return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $default, $query); } /** @@ -2541,28 +2512,27 @@ class admin_setting_configexecutable extends admin_setting_configfile { * @return string XHTML field */ public function output_html($data, $query='') { - global $CFG; + global $CFG, $OUTPUT; $default = $this->get_defaultsetting(); require_once("$CFG->libdir/filelib.php"); - if ($data) { - if (file_exists($data) and !is_dir($data) and file_is_executable($data)) { - $executable = ''; - } else { - $executable = ''; - } - } else { - $executable = ''; - } - $readonly = ''; + $context = (object) [ + 'id' => $this->get_id(), + 'name' => $this->get_full_name(), + 'size' => $this->size, + 'value' => $data, + 'showvalidity' => !empty($data), + 'valid' => $data && file_exists($data) && !is_dir($data) && file_is_executable($data), + 'readonly' => !empty($CFG->preventexecpath) + ]; + if (!empty($CFG->preventexecpath)) { $this->visiblename .= '
'.get_string('execpathnotallowed', 'admin').'
'; - $readonly = 'readonly="readonly"'; } - return format_admin_setting($this, $this->visiblename, - '
'.$executable.'
', - $this->description, true, '', $default, $query); + $element = $OUTPUT->render_from_template('core_admin/setting_configexecutable', $context); + + return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $default, $query); } } @@ -2582,27 +2552,26 @@ class admin_setting_configdirectory extends admin_setting_configfile { * @return string XHTML */ public function output_html($data, $query='') { - global $CFG; + global $CFG, $OUTPUT; $default = $this->get_defaultsetting(); - if ($data) { - if (file_exists($data) and is_dir($data)) { - $executable = ''; - } else { - $executable = ''; - } - } else { - $executable = ''; - } - $readonly = ''; + $context = (object) [ + 'id' => $this->get_id(), + 'name' => $this->get_full_name(), + 'size' => $this->size, + 'value' => $data, + 'showvalidity' => !empty($data), + 'valid' => $data && file_exists($data) && is_dir($data), + 'readonly' => !empty($CFG->preventexecpath) + ]; + if (!empty($CFG->preventexecpath)) { $this->visiblename .= '
'.get_string('execpathnotallowed', 'admin').'
'; - $readonly = 'readonly="readonly"'; } - return format_admin_setting($this, $this->visiblename, - '
'.$executable.'
', - $this->description, true, '', $default, $query); + $element = $OUTPUT->render_from_template('core_admin/setting_configexecutable', $context); + + return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $default, $query); } } @@ -2668,8 +2637,17 @@ public function write_setting($data) { * @return string XHTML field */ public function output_html($data, $query='') { - $default = $this->get_defaultsetting(); + global $OUTPUT; + + $context = (object) [ + 'id' => $this->get_id(), + 'name' => $this->get_full_name(), + 'no' => $this->no, + 'value' => $this->yes, + 'checked' => (string) $data === $this->yes, + ]; + $default = $this->get_defaultsetting(); if (!is_null($default)) { if ((string)$default === $this->yes) { $defaultinfo = get_string('checkboxyes', 'admin'); @@ -2680,16 +2658,9 @@ public function output_html($data, $query='') { $defaultinfo = NULL; } - if ((string)$data === $this->yes) { // convert to strings before comparison - $checked = 'checked="checked"'; - } else { - $checked = ''; - } + $element = $OUTPUT->render_from_template('core_admin/setting_configcheckbox', $context); - return format_admin_setting($this, $this->visiblename, - '
' - .'
', - $this->description, true, '', $defaultinfo, $query); + return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query); } } @@ -2814,9 +2785,12 @@ public function write_setting($data) { * @return string XHTML field */ public function output_html($data, $query='') { + global $OUTPUT; + if (!$this->load_choices() or empty($this->choices)) { return ''; } + $default = $this->get_defaultsetting(); if (is_null($default)) { $default = array(); @@ -2824,42 +2798,40 @@ public function output_html($data, $query='') { if (is_null($data)) { $data = array(); } + + $context = (object) [ + 'id' => $this->get_id(), + 'name' => $this->get_full_name(), + ]; + $options = array(); $defaults = array(); - foreach ($this->choices as $key=>$description) { - if (!empty($data[$key])) { - $checked = 'checked="checked"'; - } else { - $checked = ''; - } + foreach ($this->choices as $key => $description) { if (!empty($default[$key])) { $defaults[] = $description; } - $options[] = '' - .''; + $options[] = [ + 'key' => $key, + 'checked' => !empty($data[$key]), + 'label' => highlightfast($query, $description) + ]; } if (is_null($default)) { - $defaultinfo = NULL; + $defaultinfo = null; } else if (!empty($defaults)) { - $defaultinfo = implode(', ', $defaults); - } else { - $defaultinfo = get_string('none'); - } - - $return = '
'; - $return .= ''; // something must be submitted even if nothing selected - if ($options) { - $return .= '
    '; - foreach ($options as $option) { - $return .= '
  • '.$option.'
  • '; - } - $return .= '
'; + $defaultinfo = implode(', ', $defaults); + } else { + $defaultinfo = get_string('none'); } - $return .= '
'; - return format_admin_setting($this, $this->visiblename, $return, $this->description, false, '', $defaultinfo, $query); + $context->options = $options; + $context->hasoptions = !empty($options); + + $element = $OUTPUT->render_from_template('core_admin/setting_configmulticheckbox', $context); + + return format_admin_setting($this, $this->visiblename, $element, $this->description, false, '', $defaultinfo, $query); } } @@ -3024,31 +2996,10 @@ public function write_setting($data) { * @param string $current the currently selected option in the database, null if none. * @param string $default the default selected option. * @return array the HTML for the select element, and a warning message. + * @deprecated since Moodle 3.2 */ public function output_select_html($data, $current, $default, $extraname = '') { - if (!$this->load_choices() or empty($this->choices)) { - return array('', ''); - } - - $warning = ''; - if (is_null($current)) { - // first run - } else if (empty($current) and (array_key_exists('', $this->choices) or array_key_exists(0, $this->choices))) { - // no warning - } else if (!array_key_exists($current, $this->choices)) { - $warning = get_string('warningcurrentsetting', 'admin', s($current)); - if (!is_null($default) and $data == $current) { - $data = $default; // use default instead of first value when showing the form - } - } - - $selecthtml = ''; - return array($selecthtml, $warning); + debugging('The method admin_setting_configselect::output_select_html is depreacted, do not use any more.', DEBUG_DEVELOPER); } /** @@ -3061,23 +3012,52 @@ public function output_select_html($data, $current, $default, $extraname = '') { * @return string XHTML field and wrapping div */ public function output_html($data, $query='') { + global $OUTPUT; + $default = $this->get_defaultsetting(); $current = $this->get_setting(); - list($selecthtml, $warning) = $this->output_select_html($data, $current, $default); - if (!$selecthtml) { + if (!$this->load_choices() || empty($this->choices)) { return ''; } - if (!is_null($default) and array_key_exists($default, $this->choices)) { + $context = (object) [ + 'id' => $this->get_id(), + 'name' => $this->get_full_name(), + ]; + + if (!is_null($default) && array_key_exists($default, $this->choices)) { $defaultinfo = $this->choices[$default]; } else { $defaultinfo = NULL; } - $return = '
' . $selecthtml . '
'; + // Warnings. + $warning = ''; + if ($current === null) { + // First run. + } else if (empty($current) && (array_key_exists('', $this->choices) || array_key_exists(0, $this->choices))) { + // No warning. + } else if (!array_key_exists($current, $this->choices)) { + $warning = get_string('warningcurrentsetting', 'admin', $current); + if (!is_null($default) && $data == $current) { + $data = $default; // Use default instead of first value when showing the form. + } + } - return format_admin_setting($this, $this->visiblename, $return, $this->description, true, $warning, $defaultinfo, $query); + $options = []; + foreach ($this->choices as $value => $name) { + $options[] = [ + 'value' => $value, + 'name' => $name, + 'selected' => (string) $value == $data + ]; + } + $context->options = $options; + + $element = $OUTPUT->render_from_template('core_admin/setting_configselect', $context); + + return format_admin_setting($this, $this->visiblename, $element, $this->description, true, $warning, $defaultinfo, $query); } } @@ -3176,10 +3156,12 @@ public function is_related($query) { * @return string XHTML multi-select field */ public function output_html($data, $query='') { + global $OUTPUT; + if (!$this->load_choices() or empty($this->choices)) { return ''; } - $choices = $this->choices; + $default = $this->get_defaultsetting(); if (is_null($default)) { $default = array(); @@ -3188,22 +3170,25 @@ public function output_html($data, $query='') { $data = array(); } - $defaults = array(); - $size = min(10, count($this->choices)); - $return = '
'; // something must be submitted even if nothing selected - $return .= '
'; - return format_admin_setting($this, $this->visiblename, $return, $this->description, true, '', $defaultinfo, $query); + $element = $OUTPUT->render_from_template('core_admin/setting_configmultiselect', $context); + + return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query); } } @@ -3281,29 +3267,37 @@ public function write_setting($data) { * @return string XHTML time select fields and wrapping div(s) */ public function output_html($data, $query='') { - $default = $this->get_defaultsetting(); + global $OUTPUT; + $default = $this->get_defaultsetting(); if (is_array($default)) { $defaultinfo = $default['h'].':'.$default['m']; } else { $defaultinfo = NULL; } - $return = '
'; - $return .= ''; - $return .= ':'; - $return .= ''; - $return .= ''; - $return .= '
'; - return format_admin_setting($this, $this->visiblename, $return, $this->description, + $context = (object) [ + 'id' => $this->get_id(), + 'name' => $this->get_full_name(), + 'hours' => array_map(function($i) use ($data) { + return [ + 'value' => $i, + 'name' => $i, + 'selected' => $i == $data['h'] + ]; + }, range(0, 23)), + 'minutes' => array_map(function($i) use ($data) { + return [ + 'value' => $i, + 'name' => $i, + 'selected' => $i == $data['m'] + ]; + }, range(0, 59, 5)) + ]; + + $element = $OUTPUT->render_from_template('core_admin/setting_configtime', $context); + + return format_admin_setting($this, $this->visiblename, $element, $this->description, $this->get_id() . 'h', '', $defaultinfo, $query); } @@ -3440,8 +3434,9 @@ public function write_setting($data) { * @return string duration text+select fields and wrapping div(s) */ public function output_html($data, $query='') { - $default = $this->get_defaultsetting(); + global $OUTPUT; + $default = $this->get_defaultsetting(); if (is_number($default)) { $defaultinfo = self::get_duration_text($default); } else if (is_array($default)) { @@ -3450,29 +3445,26 @@ public function output_html($data, $query='') { $defaultinfo = null; } + $inputid = $this->get_id() . 'v'; $units = self::get_units(); + $defaultunit = $this->defaultunit; - $inputid = $this->get_id() . 'v'; + $context = (object) [ + 'id' => $this->get_id(), + 'name' => $this->get_full_name(), + 'value' => $data['v'], + 'options' => array_map(function($unit) use ($units, $data, $defaultunit) { + return [ + 'value' => $unit, + 'name' => $units[$unit], + 'selected' => ($data['v'] == 0 && $unit == $defaultunit) || $unit == $data['u'] + ]; + }, array_keys($units)) + ]; - $return = '
'; - $return .= ''; - $return .= ''; - $return .= '
'; - return format_admin_setting($this, $this->visiblename, $return, $this->description, $inputid, '', $defaultinfo, $query); + $element = $OUTPUT->render_from_template('core_admin/setting_configduration', $context); + + return format_admin_setting($this, $this->visiblename, $element, $this->description, $inputid, '', $defaultinfo, $query); } } @@ -3912,6 +3904,8 @@ public function write_setting($data) { * @return string XHTML select field and wrapping div */ public function output_html($data, $query='') { + global $OUTPUT; + $this->load_choices(); $currentsetting = array(); foreach ($data as $key) { @@ -3920,23 +3914,33 @@ public function output_html($data, $query='') { } } - $return = '
'; + $context = (object) [ + 'id' => $this->get_id(), + 'name' => $this->get_full_name(), + ]; + + $options = $this->choices; + $selects = []; for ($i = 0; $i < count($this->choices) - 1; $i++) { if (!array_key_exists($i, $currentsetting)) { - $currentsetting[$i] = 'none'; //none - } - $return .=''; - if ($i !== count($this->choices) - 2) { - $return .= '
'; + $currentsetting[$i] = 'none'; } + $selects[] = [ + 'key' => $i, + 'options' => array_map(function($option) use ($options, $currentsetting, $i) { + return [ + 'name' => $options[$option], + 'value' => $option, + 'selected' => $currentsetting[$i] == $option + ]; + }, array_keys($options)) + ]; } - $return .= '
'; + $context->selects = $selects; + + $element = $OUTPUT->render_from_template('core_admin/setting_courselist_frontpage', $context); - return format_admin_setting($this, $this->visiblename, $return, $this->description, false, '', NULL, $query); + return format_admin_setting($this, $this->visiblename, $element, $this->description, false, '', null, $query); } } @@ -4063,13 +4067,14 @@ public function write_setting($data) { * * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class admin_setting_special_frontpagedesc extends admin_setting { +class admin_setting_special_frontpagedesc extends admin_setting_confightmleditor { + /** * Calls parent::__construct with specific arguments */ public function __construct() { - parent::__construct('summary', get_string('frontpagedescription'), get_string('frontpagedescriptionhelp'), NULL); - editors_head_setup(); + parent::__construct('summary', get_string('frontpagedescription'), get_string('frontpagedescriptionhelp'), null, + PARAM_RAW, 60, 15); } /** @@ -4106,21 +4111,6 @@ public function write_setting($data) { return ''; } - - /** - * Returns XHTML for the field plus wrapping div - * - * @param string $data The current value - * @param string $query - * @return string The XHTML output - */ - public function output_html($data, $query='') { - global $CFG; - - $return = '
'.print_textarea(true, 15, 60, 0, 0, $this->get_full_name(), $data, 0, true, 'summary') .'
'; - - return format_admin_setting($this, $this->visiblename, $return, $this->description, false, '', NULL, $query); - } } @@ -4196,72 +4186,48 @@ public function write_setting($data) { public function output_html($data, $query='') { global $OUTPUT; - $out = html_writer::start_tag('table', array('id' => 'emoticonsetting', 'class' => 'admintable generaltable')); - $out .= html_writer::start_tag('thead'); - $out .= html_writer::start_tag('tr'); - $out .= html_writer::tag('th', get_string('emoticontext', 'admin')); - $out .= html_writer::tag('th', get_string('emoticonimagename', 'admin')); - $out .= html_writer::tag('th', get_string('emoticoncomponent', 'admin')); - $out .= html_writer::tag('th', get_string('emoticonalt', 'admin'), array('colspan' => 2)); - $out .= html_writer::tag('th', ''); - $out .= html_writer::end_tag('tr'); - $out .= html_writer::end_tag('thead'); - $out .= html_writer::start_tag('tbody'); + $context = (object) [ + 'name' => $this->get_full_name(), + 'emoticons' => [], + ]; + $i = 0; - foreach($data as $field => $value) { - switch ($i) { - case 0: - $out .= html_writer::start_tag('tr'); - $current_text = $value; - $current_filename = ''; - $current_imagecomponent = ''; - $current_altidentifier = ''; - $current_altcomponent = ''; - case 1: - $current_filename = $value; - case 2: - $current_imagecomponent = $value; - case 3: - $current_altidentifier = $value; - case 4: - $current_altcomponent = $value; - } - - $out .= html_writer::tag('td', - html_writer::empty_tag('input', - array( - 'type' => 'text', - 'class' => 'form-text', - 'name' => $this->get_full_name().'['.$field.']', - 'value' => $value, - ) - ), array('class' => 'c'.$i) - ); - - if ($i == 4) { - if (get_string_manager()->string_exists($current_altidentifier, $current_altcomponent)) { - $alt = get_string($current_altidentifier, $current_altcomponent); - } else { - $alt = $current_text; - } - if ($current_filename) { - $out .= html_writer::tag('td', $OUTPUT->render(new pix_emoticon($current_filename, $alt, $current_imagecomponent))); - } else { - $out .= html_writer::tag('td', ''); + foreach ($data as $field => $value) { + + // When $i == 0: text. + // When $i == 1: imagename. + // When $i == 2: imagecomponent. + // When $i == 3: altidentifier. + // When $i == 4: altcomponent. + $fields[$i] = (object) [ + 'field' => $field, + 'value' => $value, + 'index' => $i + ]; + $i++; + + if ($i > 4) { + $icon = null; + if (!empty($fields[1]->value)) { + if (get_string_manager()->string_exists($fields[3]->value, $fields[4]->value)) { + $alt = get_string($fields[3]->value, $fields[4]->value); + } else { + $alt = $fields[0]->value; + } + $icon = new pix_emoticon($fields[1]->value, $alt, $fields[2]->value); } - $out .= html_writer::end_tag('tr'); + $context->emoticons[] = [ + 'fields' => $fields, + 'icon' => $icon ? $icon->export_for_template($OUTPUT) : null + ]; + $fields = []; $i = 0; - } else { - $i++; } - } - $out .= html_writer::end_tag('tbody'); - $out .= html_writer::end_tag('table'); - $out = html_writer::tag('div', $out, array('class' => 'form-group')); - $out .= html_writer::tag('div', html_writer::link(new moodle_url('/admin/resetemoticons.php'), get_string('emoticonsreset', 'admin'))); - return format_admin_setting($this, $this->visiblename, $out, $this->description, false, '', NULL, $query); + $context->reseturl = new moodle_url('/admin/resetemoticons.php'); + $element = $OUTPUT->render_from_template('core_admin/setting_emoticons', $context); + return format_admin_setting($this, $this->visiblename, $element, $this->description, false, '', NULL, $query); } /** @@ -4623,20 +4589,25 @@ public function write_setting($data) { * @return string XHTML for display (field + wrapping div(s) */ public function output_html($data, $query='') { - // The order matters very much because of the implied numeric keys + global $OUTPUT; + + // The order matters very much because of the implied numeric keys. $days = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); - $return = ''; - $return .= ''; // something must be submitted even if nothing selected - foreach($days as $index => $day) { - $return .= ''; - } - $return .= ''; - foreach($days as $index => $day) { - $return .= ''; - } - $return .= '
'; + $context = (object) [ + 'name' => $this->get_full_name(), + 'id' => $this->get_id(), + 'days' => array_map(function($index) use ($days, $data) { + return [ + 'index' => $index, + 'label' => get_string($days[$index], 'calendar'), + 'checked' => in_array($index, $data) + ]; + }, array_keys($days)) + ]; - return format_admin_setting($this, $this->visiblename, $return, $this->description, false, '', NULL, $query); + $element = $OUTPUT->render_from_template('core_admin/setting_special_calendar_weekend', $context); + + return format_admin_setting($this, $this->visiblename, $element, $this->description, false, '', NULL, $query); } } @@ -5175,21 +5146,21 @@ public function validate($data) { * @return string XHTML to display control */ public function output_html($data, $query = '') { - $default = $this->get_defaultsetting(); + global $OUTPUT; - $attr = array( - 'type' => 'text', + $default = $this->get_defaultsetting(); + $context = (object) [ 'size' => $this->size, 'id' => $this->get_id(), 'name' => $this->get_full_name(), - 'value' => s($data), - 'maxlength' => '5' - ); - $input = html_writer::empty_tag('input', $attr); + 'value' => $data, + 'attributes' => [ + 'maxlength' => 5 + ] + ]; + $element = $OUTPUT->render_from_template('core_admin/setting_configtext', $context); - $attr = array('class' => 'form-text defaultsnext'); - $div = html_writer::tag('div', $input, $attr); - return format_admin_setting($this, $this->visiblename, $div, $this->description, true, '', $default, $query); + return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $default, $query); } } @@ -5286,9 +5257,9 @@ public function write_setting($data) { * @return string XHTML to display control */ public function output_html($data, $query='') { + global $OUTPUT; + $value = $data['value']; - $forced = !empty($data['forced']); - $adv = !empty($data['adv']); $default = $this->get_defaultsetting(); if (!is_null($default)) { @@ -5308,21 +5279,24 @@ public function output_html($data, $query='') { $defaultinfo = NULL; } + $options = $this->choices; + $context = (object) [ + 'id' => $this->get_id(), + 'name' => $this->get_full_name(), + 'forced' => !empty($data['forced']), + 'advanced' => !empty($data['adv']), + 'options' => array_map(function($option) use ($options, $value) { + return [ + 'value' => $option, + 'name' => $options[$option], + 'selected' => $option == $value + ]; + }, array_keys($options)), + ]; - $return = '
'; - $return .= ''; - $return .= '' - .''; - $return .= '' - .''; - $return .= '
'; + $element = $OUTPUT->render_from_template('core_admin/setting_gradecat_combo', $context); - return format_admin_setting($this, $this->visiblename, $return, $this->description, true, '', $defaultinfo, $query); + return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query); } } @@ -7540,36 +7514,36 @@ function admin_output_new_settings_by_page($node) { * @return string XHTML */ function format_admin_setting($setting, $title='', $form='', $description='', $label=true, $warning='', $defaultinfo=NULL, $query='') { - global $CFG; + global $CFG, $OUTPUT; - $name = empty($setting->plugin) ? $setting->name : "$setting->plugin | $setting->name"; - $fullname = $setting->get_full_name(); + $context = (object) [ + 'name' => empty($setting->plugin) ? $setting->name : "$setting->plugin | $setting->name", + 'fullname' => $setting->get_full_name(), + ]; - // sometimes the id is not id_s_name, but id_s_name_m or something, and this does not validate + // Sometimes the id is not id_s_name, but id_s_name_m or something, and this does not validate. if ($label === true) { - $labelfor = 'for = "'.$setting->get_id().'"'; + $context->labelfor = $setting->get_id(); } else if ($label === false) { - $labelfor = ''; + $context->labelfor = ''; } else { - $labelfor = 'for="' . $label . '"'; + $context->labelfor = $label; } + $form .= $setting->output_setting_flags(); - $override = ''; + $context->warning = $warning; + $context->override = ''; if (empty($setting->plugin)) { if (array_key_exists($setting->name, $CFG->config_php_settings)) { - $override = '
'.get_string('configoverride', 'admin').'
'; + $context->override = get_string('configoverride', 'admin'); } } else { if (array_key_exists($setting->plugin, $CFG->forced_plugin_settings) and array_key_exists($setting->name, $CFG->forced_plugin_settings[$setting->plugin])) { - $override = '
'.get_string('configoverride', 'admin').'
'; + $context->override = get_string('configoverride', 'admin'); } } - if ($warning !== '') { - $warning = '
'.$warning.'
'; - } - $defaults = array(); if (!is_null($defaultinfo)) { if ($defaultinfo === '') { @@ -7578,32 +7552,28 @@ function format_admin_setting($setting, $title='', $form='', $description='', $l $defaults[] = $defaultinfo; } + $context->default = null; $setting->get_setting_flag_defaults($defaults); - if (!empty($defaults)) { $defaultinfo = implode(', ', $defaults); $defaultinfo = highlight($query, nl2br(s($defaultinfo))); - $defaultinfo = '
'.get_string('defaultsettinginfo', 'admin', $defaultinfo).'
'; + $context->default = get_string('defaultsettinginfo', 'admin', $defaultinfo); } + $context->error = ''; $adminroot = admin_get_root(); - $error = ''; - if (array_key_exists($fullname, $adminroot->errors)) { - $error = '
' . $adminroot->errors[$fullname]->error . '
'; - } - - $str = ' -
-
- - '.highlightfast($query, $name).' -
-
'.$error.$form.$defaultinfo.'
-
'.highlight($query, markdown_to_html($description)).'
-
'; - - return $str; + if (array_key_exists($context->fullname, $adminroot->errors)) { + $context->error = $adminroot->errors[$fullname]->error; + } + + $context->id = 'admin-' . $setting->name; + $context->title = highlightfast($query, $title); + $context->name = highlightfast($query, $context->name); + $context->description = highlight($query, markdown_to_html($description)); + $context->element = $form; + + return $OUTPUT->render_from_template('core_admin/setting', $context); } /** @@ -9035,15 +9005,20 @@ protected function validate($data) { */ public function output_html($data, $query = '') { global $PAGE, $OUTPUT; + + $icon = new pix_icon('i/loading', get_string('loading', 'admin'), 'moodle', ['class'=>'loadingicon']); + $context = (object) [ + 'id' => $this->get_id(), + 'name' => $this->get_full_name(), + 'icon' => $icon->export_for_template($OUTPUT), + 'haspreviewconfig' => !empty($this->previewconfig) + ]; + + $element = $OUTPUT->render_from_template('core_admin/setting_configcolourpicker', $context); $PAGE->requires->js_init_call('M.util.init_colour_picker', array($this->get_id(), $this->previewconfig)); - $content = html_writer::start_tag('div', array('class'=>'form-colourpicker defaultsnext')); - $content .= html_writer::tag('div', $OUTPUT->pix_icon('i/loading', get_string('loading', 'admin'), 'moodle', array('class'=>'loadingicon')), array('class'=>'admin_colourpicker clearfix')); - $content .= html_writer::empty_tag('input', array('type'=>'text','id'=>$this->get_id(), 'name'=>$this->get_full_name(), 'value'=>$data, 'size'=>'12')); - if (!empty($this->previewconfig)) { - $content .= html_writer::empty_tag('input', array('type'=>'button','id'=>$this->get_id().'_preview', 'value'=>get_string('preview'), 'class'=>'admin_colourpicker_preview')); - } - $content .= html_writer::end_tag('div'); - return format_admin_setting($this, $this->visiblename, $content, $this->description, true, '', $this->get_defaultsetting(), $query); + + return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', + $this->get_defaultsetting(), $query); } } @@ -9289,14 +9264,10 @@ public function write_setting($data) { public function output_html($data, $query='') { global $OUTPUT; - $out = html_writer::start_tag('table', array('class' => 'generaltable')); - $out .= html_writer::start_tag('thead'); - $out .= html_writer::start_tag('tr'); - $out .= html_writer::tag('th', get_string('devicedetectregexexpression', 'admin')); - $out .= html_writer::tag('th', get_string('devicedetectregexvalue', 'admin')); - $out .= html_writer::end_tag('tr'); - $out .= html_writer::end_tag('thead'); - $out .= html_writer::start_tag('tbody'); + $context = (object) [ + 'expressions' => [], + 'name' => $this->get_full_name() + ]; if (empty($data)) { $looplimit = 1; @@ -9305,7 +9276,6 @@ public function output_html($data, $query='') { } for ($i=0; $i<$looplimit; $i++) { - $out .= html_writer::start_tag('tr'); $expressionname = 'expression'.$i; @@ -9315,17 +9285,6 @@ public function output_html($data, $query='') { $expression = ''; } - $out .= html_writer::tag('td', - html_writer::empty_tag('input', - array( - 'type' => 'text', - 'class' => 'form-text', - 'name' => $this->get_full_name().'[expression'.$i.']', - 'value' => $expression, - ) - ), array('class' => 'c'.$i) - ); - $valuename = 'value'.$i; if (!empty($data[$valuename])){ @@ -9334,24 +9293,16 @@ public function output_html($data, $query='') { $value= ''; } - $out .= html_writer::tag('td', - html_writer::empty_tag('input', - array( - 'type' => 'text', - 'class' => 'form-text', - 'name' => $this->get_full_name().'[value'.$i.']', - 'value' => $value, - ) - ), array('class' => 'c'.$i) - ); - - $out .= html_writer::end_tag('tr'); + $context->expressions[] = [ + 'index' => $i, + 'expression' => $expression, + 'value' => $value + ]; } - $out .= html_writer::end_tag('tbody'); - $out .= html_writer::end_tag('table'); + $element = $OUTPUT->render_from_template('core_admin/setting_devicedetectregex', $context); - return format_admin_setting($this, $this->visiblename, $out, $this->description, false, '', null, $query); + return format_admin_setting($this, $this->visiblename, $element, $this->description, false, '', null, $query); } /**