-
Bug
-
Resolution: Fixed
-
Minor
-
4.3.6, 4.4.2
-
MOODLE_403_STABLE, MOODLE_404_STABLE
-
MOODLE_403_STABLE, MOODLE_404_STABLE
-
mdl-82214-m403
-
mdl-82214-m404
-
mdl-82214
-
If you have a checkbox admin setting that is set to be read only and set to have a value of yes when you save the screen it is updated to the no state.
This appears to be happening because of[ the hidden input that is configured to no|https://github.com/moodle/moodle/blob/main/admin/templates/setting_configcheckbox.mustache#L41], when the checkbox is set to be disabled it is not submitted as part of the form.
This means that the hidden field is submitted which causes the setting to be changed.
I think that to fix this the hidden input should only be output if the setting is not read only.
I found this bug while trying to implement a setting that could not be changed via the admin UI, but which I wanted to display to the users, i.e. something like:
class admin_setting_completed extends \admin_setting_configcheckbox { |
/** |
* Constructor for the setting.
|
*
|
* @param $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
|
*/
|
public function __construct($name) { |
$visiblename = 'Completed'; |
$description = 'This setting should not change if code else where has set it to "1"'; |
parent::__construct($name, $visiblename, $description, null); |
}
|
|
/** |
* This setting is not configurable via the UI.
|
*/
|
public function is_readonly(): bool { |
return true; |
}
|
}
|
In my plugin I can workaround this by making my control by making it use it's own template
I have created a patch that will allow you to observe this in action, it adds a config element to the System paths settings page
Replication steps
- Apply the patch to the main branch
- From the root Moodle directory run php mdl-82214.php to set the setting to the yes value
- Login to Moodle as the admin
- Navigate to Site Administration > Server > System paths
- Observe the read only Completed checkbox at the bottom of the page is checked
- Press Save changes
- Observe that the read only Completed checkbox is is now not checked
There is also now a patch that demonstrated the same issue with multipcheckbox and multiselect settings.
- has been marked as being related by
-
MDL-82716 PR only: MDL-82214 - Some admin settings reset to empty when read-only and the page it is on is saved
-
- Closed
-