diff --git a/admin/classes/local/settings/filesize.php b/admin/classes/local/settings/filesize.php index e5a6edbaf90..3352f1ec375 100644 --- a/admin/classes/local/settings/filesize.php +++ b/admin/classes/local/settings/filesize.php @@ -178,6 +178,7 @@ class filesize extends \admin_setting { 'id' => $this->get_id(), 'name' => $this->get_full_name(), 'value' => $data['v'], + 'readonly' => $this->is_readonly(), 'options' => array_map(function($unit, $title) use ($data, $defaultunit) { return [ 'value' => $unit, diff --git a/admin/templates/setting_configcheckbox.mustache b/admin/templates/setting_configcheckbox.mustache index f41e5a27fbc..48e0471ee27 100644 --- a/admin/templates/setting_configcheckbox.mustache +++ b/admin/templates/setting_configcheckbox.mustache @@ -25,6 +25,7 @@ * value - yes value * id - element id * checked - boole + * readonly - bool Example context (json): { @@ -32,10 +33,11 @@ "no": "False", "value": "True", "id": "test0", - "checked": "checked" + "checked": "checked", + "readonly": false } }}
- +
diff --git a/admin/templates/setting_configcolourpicker.mustache b/admin/templates/setting_configcolourpicker.mustache index 3de5aac311d..50b7da1011b 100644 --- a/admin/templates/setting_configcolourpicker.mustache +++ b/admin/templates/setting_configcolourpicker.mustache @@ -25,6 +25,7 @@ * id - element id * value - element value * haspreviewconfig - show preview of selected color + * readonly - bool Example context (json): { @@ -32,6 +33,7 @@ "name": "name0", "id": "id0", "value": "#555655", + "readonly": false, "haspreviewconfig": false } }} @@ -44,7 +46,7 @@ {{>core/pix_icon}} {{/icon}} - + {{#haspreviewconfig}} {{/haspreviewconfig}} diff --git a/admin/templates/setting_configdirectory.mustache b/admin/templates/setting_configdirectory.mustache index 18047876140..cfe8a7d6484 100644 --- a/admin/templates/setting_configdirectory.mustache +++ b/admin/templates/setting_configdirectory.mustache @@ -33,7 +33,7 @@ "name": "test", "value": "/my-super-secret-path/", "id": "test0", - "readonly": true, + "readonly": false, "showvalidity": true, "valid": false } diff --git a/admin/templates/setting_configduration.mustache b/admin/templates/setting_configduration.mustache index d20dabc090b..1a880c10d81 100644 --- a/admin/templates/setting_configduration.mustache +++ b/admin/templates/setting_configduration.mustache @@ -23,6 +23,7 @@ * name - form element name * options - list of options for units containing name, value, selected * value - yes + * readonly - bool * id - element id Example context (json): @@ -30,6 +31,7 @@ "name": "test", "value": "5", "id": "test0", + "readonly": false, "options": [ { "name": "Minutes", "value": "mins", "selected": true } ] } }} @@ -38,9 +40,9 @@ }}
- + - {{#options}} {{/options}} diff --git a/admin/templates/setting_configexecutable.mustache b/admin/templates/setting_configexecutable.mustache index 72187f205e6..773b07d4df3 100644 --- a/admin/templates/setting_configexecutable.mustache +++ b/admin/templates/setting_configexecutable.mustache @@ -33,7 +33,7 @@ "name": "test", "value": "/usr/bin/cowsay", "id": "test0", - "readonly": true, + "readonly": false, "showvalidity": true, "valid": false } diff --git a/admin/templates/setting_configfile.mustache b/admin/templates/setting_configfile.mustache index 1f0b5d5d6b8..15a45ce70a6 100644 --- a/admin/templates/setting_configfile.mustache +++ b/admin/templates/setting_configfile.mustache @@ -26,6 +26,7 @@ * readonly - Make the field readonly * value - value * showvalidity - Show a green check if the path is readable + * readonly - bool * valid - True if the path is readable Example context (json): @@ -33,8 +34,9 @@ "name": "test", "value": "/my-super-secret-path/file", "id": "test0", - "readonly": true, + "readonly": false, "showvalidity": true, + "readonly": false, "valid": false } }} diff --git a/admin/templates/setting_configfilesize.mustache b/admin/templates/setting_configfilesize.mustache index 4716c6ea0dd..355cc6d52ef 100644 --- a/admin/templates/setting_configfilesize.mustache +++ b/admin/templates/setting_configfilesize.mustache @@ -24,12 +24,14 @@ * options - list of options for units containing name, value, selected * value - yes * id - element id + * readonly - bool Example context (json): { "name": "test", "value": "5", "id": "test0", + "readonly": false, "options": [ { "name": "KB", "value": "1024", "selected": true } ] } }} @@ -38,9 +40,9 @@ }}
- + - {{#options}} {{/options}} diff --git a/admin/templates/setting_configmultiselect.mustache b/admin/templates/setting_configmultiselect.mustache index 49eb55c1e74..c19b1fd7f8b 100644 --- a/admin/templates/setting_configmultiselect.mustache +++ b/admin/templates/setting_configmultiselect.mustache @@ -24,11 +24,13 @@ * id - element id * size - element size * options - list of options containing name, value, selected + * readonly - bool Example context (json): { "name": "test", "id": "test0", + "readonly": false, "size": "3", "options": [ { "name": "Option 1", "value": "V", "selected": true }, { "name": "Option 2", "value": "V", "selected": true } ] @@ -39,7 +41,7 @@ }}
- {{#options}} {{/options}} diff --git a/admin/templates/setting_configmultiselect_optgroup.mustache b/admin/templates/setting_configmultiselect_optgroup.mustache index 20d66e1226c..a1cbc9d7ee3 100644 --- a/admin/templates/setting_configmultiselect_optgroup.mustache +++ b/admin/templates/setting_configmultiselect_optgroup.mustache @@ -25,11 +25,13 @@ * size - element size * options - list of options not grouped * optgroups - list of options grouped containing the group label and for each option: name, value, selected + * readonly - bool Example context (json): { "name": "test", "id": "test0", + "readonly": false, "size": "3", "options": [ { "name": "Option 1", "value": "V", "selected": false }, @@ -58,7 +60,7 @@ }}
- {{#options}} {{/options}} diff --git a/admin/templates/setting_configpasswordunmask.mustache b/admin/templates/setting_configpasswordunmask.mustache index 7092e820a65..84a27a61769 100644 --- a/admin/templates/setting_configpasswordunmask.mustache +++ b/admin/templates/setting_configpasswordunmask.mustache @@ -24,7 +24,7 @@ * size - form element size * value - form element value * id - element id - * forced - has value been defined in config.php + * readonly - has value been defined in config.php Example context (json): { @@ -32,10 +32,10 @@ "id": "test0", "size": "8", "value": "secret", - "forced": false + "readonly": false } }} -{{#forced}} +{{#readonly}}
-{{/forced}} -{{^forced}} +{{/readonly}} +{{^readonly}}
@@ -76,4 +76,4 @@ require(['core_form/passwordunmask'], function(PasswordUnmask) { new PasswordUnmask("{{ id }}"); }); {{/js}} -{{/forced}} +{{/readonly}} diff --git a/admin/templates/setting_configselect.mustache b/admin/templates/setting_configselect.mustache index 9b6c6e1f793..eb18b4b803c 100644 --- a/admin/templates/setting_configselect.mustache +++ b/admin/templates/setting_configselect.mustache @@ -23,11 +23,13 @@ * name - form element name * id - element id * options - list of options containing name, value, selected + * readonly - bool Example context (json): { "name": "test", "id": "test0", + "readonly": false, "options": [ { "name": "Option 1", "value": "V", "selected": true }, { "name": "Option 2", "value": "V", "selected": true } @@ -38,7 +40,7 @@ Setting configselect. }}
- {{#options}} {{/options}} diff --git a/admin/templates/setting_configselect_optgroup.mustache b/admin/templates/setting_configselect_optgroup.mustache index 95f818baa7e..862ac6126e4 100644 --- a/admin/templates/setting_configselect_optgroup.mustache +++ b/admin/templates/setting_configselect_optgroup.mustache @@ -22,6 +22,7 @@ Context variables required for this template: * name - form element name * id - element id + * readonly - bool * options - list of options (not grouped) * optgroups - list of options grouped containing the group label and for each option: name, value, selected @@ -29,6 +30,7 @@ { "name": "test", "id": "test0", + "readonly": false, "options": [ { "name": "Option 1", "value": "V", "selected": false }, { "name": "Option 2", "value": "V", "selected": false } @@ -55,7 +57,7 @@ Setting configselect with optgroup support. }}
- {{#options}} {{/options}} diff --git a/admin/templates/setting_configtext.mustache b/admin/templates/setting_configtext.mustache index a31f73a3355..1238c8e3e98 100644 --- a/admin/templates/setting_configtext.mustache +++ b/admin/templates/setting_configtext.mustache @@ -26,6 +26,7 @@ * size - element size * forceltr - always display as ltr * attributes - list of additional attributes containing name, value + * readonly - bool Example context (json): { @@ -34,6 +35,7 @@ "value": "A tall, dark stranger will have more fun than you.", "size": "21", "forceltr": false, + "readonly": false, "attributes": [ { "name": "readonly", "value": "readonly" } ] } }} @@ -41,5 +43,5 @@ Setting configtext. }}
- +
diff --git a/admin/templates/setting_configtextarea.mustache b/admin/templates/setting_configtextarea.mustache index 002b0cd7e2d..c877d94cc3d 100644 --- a/admin/templates/setting_configtextarea.mustache +++ b/admin/templates/setting_configtextarea.mustache @@ -33,6 +33,7 @@ "cols": "30", "rows": "3", "value": "Excellent day for putting Slinkies on an escalator.", + "readonly": false, "id": "test0" } }} @@ -40,5 +41,5 @@ Setting configtextarea. }}
- +
diff --git a/admin/templates/setting_configtime.mustache b/admin/templates/setting_configtime.mustache index 90d37b325d5..af4435ae484 100644 --- a/admin/templates/setting_configtime.mustache +++ b/admin/templates/setting_configtime.mustache @@ -24,11 +24,13 @@ * id - element id * hours - list of valid hour options containing name, value, selected * minutes - list of valid minute options containing name, value, selected + * readonly - bool Example context (json): { "name": "test", "id": "test0", + "readonly": false, "minutes": [ { "name": "00", "value": "0", "selected": true }, { "name": "01", "value": "1", "selected": false } @@ -45,13 +47,13 @@
- {{#hours}} {{/hours}} : - {{#minutes}} {{/minutes}} diff --git a/lib/adminlib.php b/lib/adminlib.php index f51f740fc84..6764caf9af2 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -1761,6 +1761,27 @@ abstract class admin_setting { $this->set_flag_options($enabled, $default, 'required', new lang_string('required', 'core_admin')); } + /** + * Is this option forced in config.php? + * + * @return bool + */ + public function is_readonly(): bool { + global $CFG; + + if (empty($this->plugin)) { + if (array_key_exists($this->name, $CFG->config_php_settings)) { + return true; + } + } else { + if (array_key_exists($this->plugin, $CFG->forced_plugin_settings) + and array_key_exists($this->name, $CFG->forced_plugin_settings[$this->plugin])) { + return true; + } + } + return false; + } + /** * Get the currently saved value for a setting flag * @@ -2460,6 +2481,7 @@ class admin_setting_configtext extends admin_setting { 'name' => $this->get_full_name(), 'value' => $data, 'forceltr' => $this->get_force_ltr(), + 'readonly' => $this->is_readonly(), ]; $element = $OUTPUT->render_from_template('core_admin/setting_configtext', $context); @@ -2568,6 +2590,7 @@ class admin_setting_configtextarea extends admin_setting_configtext { 'name' => $this->get_full_name(), 'value' => $data, 'forceltr' => $this->get_force_ltr(), + 'readonly' => $this->is_readonly(), ]; $element = $OUTPUT->render_from_template('core_admin/setting_configtextarea', $context); @@ -2664,25 +2687,15 @@ class admin_setting_configpasswordunmask extends admin_setting_configtext { * @return string Rendered HTML */ public function output_html($data, $query='') { - global $OUTPUT, $CFG; - $forced = false; - if (empty($this->plugin)) { - if (array_key_exists($this->name, $CFG->config_php_settings)) { - $forced = true; - } - } else { - if (array_key_exists($this->plugin, $CFG->forced_plugin_settings) - and array_key_exists($this->name, $CFG->forced_plugin_settings[$this->plugin])) { - $forced = true; - } - } + global $OUTPUT; + $context = (object) [ 'id' => $this->get_id(), 'name' => $this->get_full_name(), 'size' => $this->size, - 'value' => $forced ? null : $data, + 'value' => $this->is_readonly() ? null : $data, 'forceltr' => $this->get_force_ltr(), - 'forced' => $forced + 'readonly' => $this->is_readonly(), ]; $element = $OUTPUT->render_from_template('core_admin/setting_configpasswordunmask', $context); return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', null, $query); @@ -2787,7 +2800,7 @@ class admin_setting_configfile extends admin_setting_configtext { 'value' => $data, 'showvalidity' => !empty($data), 'valid' => $data && file_exists($data), - 'readonly' => !empty($CFG->preventexecpath), + 'readonly' => !empty($CFG->preventexecpath) || $this->is_readonly(), 'forceltr' => $this->get_force_ltr(), ]; @@ -2972,6 +2985,7 @@ class admin_setting_configcheckbox extends admin_setting { 'no' => $this->no, 'value' => $this->yes, 'checked' => (string) $data === $this->yes, + 'readonly' => $this->is_readonly(), ]; $default = $this->get_defaultsetting(); @@ -3463,6 +3477,7 @@ class admin_setting_configselect extends admin_setting { ]; } $context->options = $options; + $context->readonly = $this->is_readonly(); $element = $OUTPUT->render_from_template($template, $context); @@ -3620,6 +3635,7 @@ class admin_setting_configmultiselect extends admin_setting_configselect { ]; } $context->options = $options; + $context->readonly = $this->is_readonly(); if (is_null($default)) { $defaultinfo = NULL; @@ -3710,6 +3726,7 @@ class admin_setting_configtime extends admin_setting { $context = (object) [ 'id' => $this->get_id(), 'name' => $this->get_full_name(), + 'readonly' => $this->is_readonly(), 'hours' => array_map(function($i) use ($data) { return [ 'value' => $i, @@ -3884,6 +3901,7 @@ class admin_setting_configduration extends admin_setting { 'id' => $this->get_id(), 'name' => $this->get_full_name(), 'value' => $data['v'], + 'readonly' => $this->is_readonly(), 'options' => array_map(function($unit) use ($units, $data, $defaultunit) { return [ 'value' => $unit, @@ -10536,7 +10554,8 @@ class admin_setting_configcolourpicker extends admin_setting { 'value' => $data, 'icon' => $icon->export_for_template($OUTPUT), 'haspreviewconfig' => !empty($this->previewconfig), - 'forceltr' => $this->get_force_ltr() + 'forceltr' => $this->get_force_ltr(), + 'readonly' => $this->is_readonly(), ]; $element = $OUTPUT->render_from_template('core_admin/setting_configcolourpicker', $context);