'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,
* value - yes value
* id - element id
* checked - boole
+ * readonly - bool
Example context (json):
{
"no": "False",
"value": "True",
"id": "test0",
- "checked": "checked"
+ "checked": "checked",
+ "readonly": false
}
}}
<div class="form-checkbox defaultsnext">
<input type="hidden" name="{{name}}" value="{{no}}">
- <input type="checkbox" name="{{name}}" value="{{value}}" id="{{id}}" {{#checked}}checked{{/checked}}>
+ <input {{#readonly}}disabled{{/readonly}} type="checkbox" name="{{name}}" value="{{value}}" id="{{id}}" {{#checked}}checked{{/checked}}>
</div>
* id - element id
* value - element value
* haspreviewconfig - show preview of selected color
+ * readonly - bool
Example context (json):
{
"name": "name0",
"id": "id0",
"value": "#555655",
+ "readonly": false,
"haspreviewconfig": false
}
}}
{{>core/pix_icon}}
{{/icon}}
</div>
- <input type="text" name="{{name}}" id="{{id}}" value="{{value}}" size="12" class="form-control text-ltr">
+ <input type="text" name="{{name}}" id="{{id}}" value="{{value}}" size="12" class="form-control text-ltr" {{#readonly}}disabled{{/readonly}}>
{{#haspreviewconfig}}
<input type="button" id="{{id}}_preview" value={{#quote}}{{#str}}preview{{/str}}{{/quote}} class="admin_colourpicker_preview">
{{/haspreviewconfig}}
"name": "test",
"value": "/my-super-secret-path/",
"id": "test0",
- "readonly": true,
+ "readonly": false,
"showvalidity": true,
"valid": false
}
* name - form element name
* options - list of options for units containing name, value, selected
* value - yes
+ * readonly - bool
* id - element id
Example context (json):
"name": "test",
"value": "5",
"id": "test0",
+ "readonly": false,
"options": [ { "name": "Minutes", "value": "mins", "selected": true } ]
}
}}
}}
<div class="form-duration defaultsnext">
<div class="form-inline">
- <input type="text" size="5" id="{{id}}v" name="{{name}}[v]" value="{{value}}" class="form-control text-ltr">
+ <input type="text" size="5" id="{{id}}v" name="{{name}}[v]" value="{{value}}" class="form-control text-ltr" {{#readonly}}disabled{{/readonly}}>
<label class="sr-only" for="{{id}}u">{{#str}}durationunits, admin{{/str}}</label>
- <select id="{{id}}u" name="{{name}}[u]" class="form-control custom-select">
+ <select id="{{id}}u" name="{{name}}[u]" class="form-control custom-select" {{#readonly}}disabled{{/readonly}}>
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
"name": "test",
"value": "/usr/bin/cowsay",
"id": "test0",
- "readonly": true,
+ "readonly": false,
"showvalidity": true,
"valid": false
}
* 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):
"name": "test",
"value": "/my-super-secret-path/file",
"id": "test0",
- "readonly": true,
+ "readonly": false,
"showvalidity": true,
+ "readonly": false,
"valid": false
}
}}
* 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 } ]
}
}}
}}
<div class="form-filesize defaultsnext">
<div class="form-inline">
- <input type="text" size="5" id="{{id}}v" name="{{name}}[v]" value="{{value}}" class="form-control text-ltr">
+ <input type="text" size="5" id="{{id}}v" name="{{name}}[v]" value="{{value}}" class="form-control text-ltr" {{#readonly}}disabled{{/readonly}}>
<label class="sr-only" for="{{id}}u">{{#str}}filesizeunits, admin{{/str}}</label>
- <select id="{{id}}u" name="{{name}}[u]" class="form-control custom-select">
+ <select id="{{id}}u" name="{{name}}[u]" class="form-control custom-select" {{#readonly}}disabled{{/readonly}}>
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
* 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 } ]
}}
<div class="form-select">
<input type="hidden" name="{{name}}[xxxxx]" value="1">
- <select id="{{id}}" name="{{name}}[]" size="{{size}}" class="form-control" multiple>
+ <select {{#readonly}}disabled{{/readonly}} id="{{id}}" name="{{name}}[]" size="{{size}}" class="form-control" multiple>
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
* 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 },
}}
<div class="form-select">
<input type="hidden" name="{{name}}[xxxxx]" value="1">
- <select id="{{id}}" name="{{name}}[]" size="{{size}}" class="form-control" multiple>
+ <select {{#readonly}}disabled{{/readonly}} id="{{id}}" name="{{name}}[]" size="{{size}}" class="form-control" multiple>
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
* 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):
{
"id": "test0",
"size": "8",
"value": "secret",
- "forced": false
+ "readonly": false
}
}}
-{{#forced}}
+{{#readonly}}
<div class="form-password">
<input type="text"
name = "{{ name }}"
disabled
>
</div>
-{{/forced}}
-{{^forced}}
+{{/readonly}}
+{{^readonly}}
<div class="form-password">
<span data-passwordunmask="wrapper" data-passwordunmaskid="{{ id }}">
<span data-passwordunmask="editor">
new PasswordUnmask("{{ id }}");
});
{{/js}}
-{{/forced}}
+{{/readonly}}
* 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 }
Setting configselect.
}}
<div class="form-select defaultsnext">
- <select id="{{id}}" name="{{name}}" class="custom-select">
+ <select {{#readonly}}disabled{{/readonly}} id="{{id}}" name="{{name}}" class="custom-select">
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
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
{
"name": "test",
"id": "test0",
+ "readonly": false,
"options": [
{ "name": "Option 1", "value": "V", "selected": false },
{ "name": "Option 2", "value": "V", "selected": false }
Setting configselect with optgroup support.
}}
<div class="form-select defaultsnext">
- <select id="{{id}}" name="{{name}}" class="custom-select">
+ <select {{#readonly}}disabled{{/readonly}} id="{{id}}" name="{{name}}" class="custom-select">
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
* size - element size
* forceltr - always display as ltr
* attributes - list of additional attributes containing name, value
+ * readonly - bool
Example context (json):
{
"value": "A tall, dark stranger will have more fun than you.",
"size": "21",
"forceltr": false,
+ "readonly": false,
"attributes": [ { "name": "readonly", "value": "readonly" } ]
}
}}
Setting configtext.
}}
<div class="form-text defaultsnext">
- <input type="text" name="{{name}}" value="{{value}}" size="{{size}}" id="{{id}}" class="form-control {{#forceltr}}text-ltr{{/forceltr}}">
+ <input type="text" name="{{name}}" value="{{value}}" size="{{size}}" id="{{id}}" class="form-control {{#forceltr}}text-ltr{{/forceltr}}" {{#readonly}}disabled{{/readonly}}>
</div>
"cols": "30",
"rows": "3",
"value": "Excellent day for putting Slinkies on an escalator.",
+ "readonly": false,
"id": "test0"
}
}}
Setting configtextarea.
}}
<div class="form-textarea">
- <textarea rows="{{rows}}" cols="{{cols}}" id="{{id}}" name="{{name}}" spellcheck="true" class="form-control {{#forceltr}}text-ltr{{/forceltr}}">{{value}}</textarea>
+ <textarea {{#readonly}}disabled{{/readonly}} rows="{{rows}}" cols="{{cols}}" id="{{id}}" name="{{name}}" spellcheck="true" class="form-control {{#forceltr}}text-ltr{{/forceltr}}">{{value}}</textarea>
</div>
* 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 }
<div class="form-time defaultsnext">
<div class="form-inline text-ltr">
<label class="sr-only" for="{{id}}h">{{#str}}hours{{/str}}</label>
- <select id="{{id}}h" name="{{name}}[h]" class="custom-select">
+ <select id="{{id}}h" name="{{name}}[h]" class="custom-select" {{#readonly}}disabled{{/readonly}}>
{{#hours}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/hours}}
</select>:
<label class="sr-only" for="{{id}}m">{{#str}}minutes{{/str}}</label>
- <select id="{{id}}m" name="{{name}}[m]" class="custom-select">
+ <select id="{{id}}m" name="{{name}}[m]" class="custom-select" {{#readonly}}disabled{{/readonly}}>
{{#minutes}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/minutes}}
$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
*
'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);
'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);
* @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);
'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(),
];
'no' => $this->no,
'value' => $this->yes,
'checked' => (string) $data === $this->yes,
+ 'readonly' => $this->is_readonly(),
];
$default = $this->get_defaultsetting();
];
}
$context->options = $options;
+ $context->readonly = $this->is_readonly();
$element = $OUTPUT->render_from_template($template, $context);
];
}
$context->options = $options;
+ $context->readonly = $this->is_readonly();
if (is_null($default)) {
$defaultinfo = NULL;
$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,
'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,
'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);