Skip to content

Commit 7a0bf1b

Browse files
committed
MDL-37812 user: separate preferences into separate section in editform
1 parent 4de51c2 commit 7a0bf1b

File tree

2 files changed

+86
-71
lines changed

2 files changed

+86
-71
lines changed

admin/tool/behat/tests/behat/manipulate_forms.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Feature: Forms manipulation
1111
When I set the field "First name" to "Field value"
1212
And I set the field "Text editor" to "Plain text area"
1313
And I set the field "Unmask" to "1"
14+
And I expand all fieldsets
1415
Then the field "First name" matches value "Field value"
1516
And the "Text editor" select box should contain "Plain text area"
1617
And the field "Unmask" matches value "1"

user/editlib.php

Lines changed: 85 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -218,72 +218,6 @@ function useredit_shared_definition(&$mform, $editoroptions = null, $filemanager
218218
$mform->setType('email', PARAM_EMAIL);
219219
}
220220

221-
$choices = array();
222-
$choices['0'] = get_string('emaildisplayno');
223-
$choices['1'] = get_string('emaildisplayyes');
224-
$choices['2'] = get_string('emaildisplaycourse');
225-
$mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
226-
$mform->setDefault('maildisplay', 2);
227-
228-
$choices = array();
229-
$choices['0'] = get_string('textformat');
230-
$choices['1'] = get_string('htmlformat');
231-
$mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
232-
$mform->setDefault('mailformat', 1);
233-
234-
if (!empty($CFG->allowusermailcharset)) {
235-
$choices = array();
236-
$charsets = get_list_of_charsets();
237-
if (!empty($CFG->sitemailcharset)) {
238-
$choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
239-
} else {
240-
$choices['0'] = get_string('site').' (UTF-8)';
241-
}
242-
$choices = array_merge($choices, $charsets);
243-
$mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
244-
}
245-
246-
$choices = array();
247-
$choices['0'] = get_string('emaildigestoff');
248-
$choices['1'] = get_string('emaildigestcomplete');
249-
$choices['2'] = get_string('emaildigestsubjects');
250-
$mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
251-
$mform->setDefault('maildigest', 0);
252-
$mform->addHelpButton('maildigest', 'emaildigest');
253-
254-
$choices = array();
255-
$choices['1'] = get_string('autosubscribeyes');
256-
$choices['0'] = get_string('autosubscribeno');
257-
$mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
258-
$mform->setDefault('autosubscribe', 1);
259-
260-
if (!empty($CFG->forum_trackreadposts)) {
261-
$choices = array();
262-
$choices['0'] = get_string('trackforumsno');
263-
$choices['1'] = get_string('trackforumsyes');
264-
$mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
265-
$mform->setDefault('trackforums', 0);
266-
}
267-
268-
$editors = editors_get_enabled();
269-
if (count($editors) > 1) {
270-
$choices = array('' => get_string('defaulteditor'));
271-
$firsteditor = '';
272-
foreach (array_keys($editors) as $editor) {
273-
if (!$firsteditor) {
274-
$firsteditor = $editor;
275-
}
276-
$choices[$editor] = get_string('pluginname', 'editor_' . $editor);
277-
}
278-
$mform->addElement('select', 'preference_htmleditor', get_string('textediting'), $choices);
279-
$mform->setDefault('preference_htmleditor', '');
280-
} else {
281-
// Empty string means use the first chosen text editor.
282-
$mform->addElement('hidden', 'preference_htmleditor');
283-
$mform->setDefault('preference_htmleditor', '');
284-
$mform->setType('preference_htmleditor', PARAM_PLUGIN);
285-
}
286-
287221
$mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"');
288222
$mform->setType('city', PARAM_TEXT);
289223
if (!empty($CFG->defaultcity)) {
@@ -306,9 +240,6 @@ function useredit_shared_definition(&$mform, $editoroptions = null, $filemanager
306240
$mform->setDefault('timezone', '99');
307241
}
308242

309-
$mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
310-
$mform->setDefault('lang', $CFG->lang);
311-
312243
// Multi-Calendar Support - see MDL-18375.
313244
$calendartypes = \core_calendar\type_factory::get_list_of_calendar_types();
314245
// We do not want to show this option unless there is more than one calendar type to display.
@@ -333,6 +264,9 @@ function useredit_shared_definition(&$mform, $editoroptions = null, $filemanager
333264
$mform->setType('description_editor', PARAM_CLEANHTML);
334265
$mform->addHelpButton('description_editor', 'userdescription');
335266

267+
$mform->addElement('header', 'moodle_userpreferences', get_string('preferences'));
268+
useredit_shared_definition_preferences($user, $mform, $editoroptions, $filemanageroptions);
269+
336270
if (empty($USER->newadminuser)) {
337271
$mform->addElement('header', 'moodle_picture', get_string('pictureofuser'));
338272

@@ -409,6 +343,88 @@ function useredit_shared_definition(&$mform, $editoroptions = null, $filemanager
409343
$mform->setType('address', PARAM_TEXT);
410344
}
411345

346+
/**
347+
* Adds user preferences elements to user edit form.
348+
*
349+
* @param stdClass $user
350+
* @param moodleform $mform
351+
* @param array|null $editoroptions
352+
* @param array|null $filemanageroptions
353+
*/
354+
function useredit_shared_definition_preferences($user, &$mform, $editoroptions = null, $filemanageroptions = null) {
355+
global $CFG;
356+
357+
$choices = array();
358+
$choices['0'] = get_string('emaildisplayno');
359+
$choices['1'] = get_string('emaildisplayyes');
360+
$choices['2'] = get_string('emaildisplaycourse');
361+
$mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
362+
$mform->setDefault('maildisplay', 2);
363+
364+
$choices = array();
365+
$choices['0'] = get_string('textformat');
366+
$choices['1'] = get_string('htmlformat');
367+
$mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
368+
$mform->setDefault('mailformat', 1);
369+
370+
if (!empty($CFG->allowusermailcharset)) {
371+
$choices = array();
372+
$charsets = get_list_of_charsets();
373+
if (!empty($CFG->sitemailcharset)) {
374+
$choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
375+
} else {
376+
$choices['0'] = get_string('site').' (UTF-8)';
377+
}
378+
$choices = array_merge($choices, $charsets);
379+
$mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
380+
}
381+
382+
$choices = array();
383+
$choices['0'] = get_string('emaildigestoff');
384+
$choices['1'] = get_string('emaildigestcomplete');
385+
$choices['2'] = get_string('emaildigestsubjects');
386+
$mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
387+
$mform->setDefault('maildigest', 0);
388+
$mform->addHelpButton('maildigest', 'emaildigest');
389+
390+
$choices = array();
391+
$choices['1'] = get_string('autosubscribeyes');
392+
$choices['0'] = get_string('autosubscribeno');
393+
$mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
394+
$mform->setDefault('autosubscribe', 1);
395+
396+
if (!empty($CFG->forum_trackreadposts)) {
397+
$choices = array();
398+
$choices['0'] = get_string('trackforumsno');
399+
$choices['1'] = get_string('trackforumsyes');
400+
$mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
401+
$mform->setDefault('trackforums', 0);
402+
}
403+
404+
$editors = editors_get_enabled();
405+
if (count($editors) > 1) {
406+
$choices = array('' => get_string('defaulteditor'));
407+
$firsteditor = '';
408+
foreach (array_keys($editors) as $editor) {
409+
if (!$firsteditor) {
410+
$firsteditor = $editor;
411+
}
412+
$choices[$editor] = get_string('pluginname', 'editor_' . $editor);
413+
}
414+
$mform->addElement('select', 'preference_htmleditor', get_string('textediting'), $choices);
415+
$mform->setDefault('preference_htmleditor', '');
416+
} else {
417+
// Empty string means use the first chosen text editor.
418+
$mform->addElement('hidden', 'preference_htmleditor');
419+
$mform->setDefault('preference_htmleditor', '');
420+
$mform->setType('preference_htmleditor', PARAM_PLUGIN);
421+
}
422+
423+
$mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
424+
$mform->setDefault('lang', $CFG->lang);
425+
426+
}
427+
412428
/**
413429
* Return required user name fields for forms.
414430
*
@@ -482,5 +498,3 @@ function useredit_get_disabled_name_fields($enabledadditionalusernames = null) {
482498
array_merge(array('firstname', 'lastname'), $enabledadditionalusernames));
483499
return $nonusednamefields;
484500
}
485-
486-

0 commit comments

Comments
 (0)