MDL-76974 user: deprecate old method of setting user preferences.
The `M.util.set_user_preference` method (plus accompanying helpers) are now deprecated, in favour of the `core_user/repository` module to achieve the same. Update current implementation to proxy calls to the new API ensuring backwards compatibility, while emitting copious developer debugging.
This commit is contained in:
@@ -195,27 +195,16 @@ M.util.CollapsibleRegion.prototype.icon = null;
|
||||
* user_preference_allow_ajax_update from moodlelib.php to tell Moodle that
|
||||
* the udpate is allowed, and how to safely clean and submitted values.
|
||||
*
|
||||
* @param String name the name of the setting to udpate.
|
||||
* @param String the value to set it to.
|
||||
* @param {String} name the name of the setting to update.
|
||||
* @param {String} value the value to set it to.
|
||||
*
|
||||
* @deprecated since Moodle 4.3.
|
||||
*/
|
||||
M.util.set_user_preference = function(name, value) {
|
||||
YUI().use('io', function(Y) {
|
||||
var url = M.cfg.wwwroot + '/lib/ajax/setuserpref.php?sesskey=' +
|
||||
M.cfg.sesskey + '&pref=' + encodeURI(name) + '&value=' + encodeURI(value);
|
||||
Y.log('M.util.set_user_preference is deprecated. Please use the "core_user/repository" module instead.', 'warn');
|
||||
|
||||
// If we are a developer, ensure that failures are reported.
|
||||
var cfg = {
|
||||
method: 'get',
|
||||
on: {}
|
||||
};
|
||||
if (M.cfg.developerdebug) {
|
||||
cfg.on.failure = function(id, o, args) {
|
||||
alert("Error updating user preference '" + name + "' using ajax. Clicking this link will repeat the Ajax call that failed so you can see the error: ");
|
||||
}
|
||||
}
|
||||
|
||||
// Make the request.
|
||||
Y.io(url, cfg);
|
||||
require(['core_user/repository'], function(UserRepository) {
|
||||
UserRepository.setUserPreference(name, value);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user