$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,
parent::__construct('langlist', get_string('langlist', 'admin'), get_string('configlanglist', 'admin'), '', PARAM_NOTAGS);
}
+ /**
+ * Validate that each language identifier exists on the site
+ *
+ * @param string $data
+ * @return bool|string True if validation successful, otherwise error string
+ */
+ public function validate($data) {
+ $parentcheck = parent::validate($data);
+ if ($parentcheck !== true) {
+ return $parentcheck;
+ }
+
+ if ($data === '') {
+ return true;
+ }
+
+ // Normalize language identifiers.
+ $langcodes = array_map('trim', explode(',', $data));
+ foreach ($langcodes as $langcode) {
+ // If the langcode contains optional alias, split it out.
+ [$langcode, ] = preg_split('/\s*\|\s*/', $langcode, 2);
+
+ if (!get_string_manager()->translation_exists($langcode)) {
+ return get_string('invalidlanguagecode', 'error', $langcode);
+ }
+ }
+
+ return true;
+ }
+
/**
* Save the new 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);