MDL-56601 core_user: Disable profile picture field if user is not setup

Sometimes it is possible that a user is presented with the profile
edit form, but is in a state where they are not considered fully
set up (one example is when a site is installed using the CLI script)

In these cases the filepicker gets upset when the user tries
to upload a profile picture.

This patch simply disables that field in these cases and replaces it
with an error message explaining what's wrong.
This commit is contained in:
Cameron Ball
2016-11-08 12:13:51 +08:00
parent c9af13123d
commit c86500a4b7
2 changed files with 21 additions and 1 deletions
+20 -1
View File
@@ -45,6 +45,7 @@ class user_edit_form extends moodleform {
$mform = $this->_form;
$editoroptions = null;
$filemanageroptions = null;
$usernotfullysetup = user_not_fully_set_up($USER);
if (!is_array($this->_customdata)) {
throw new coding_exception('invalid custom data for user_edit_form');
@@ -76,12 +77,30 @@ class user_edit_form extends moodleform {
useredit_shared_definition($mform, $editoroptions, $filemanageroptions, $user);
// Extra settigs.
if (!empty($CFG->disableuserimages)) {
if (!empty($CFG->disableuserimages) || $usernotfullysetup) {
$mform->removeElement('deletepicture');
$mform->removeElement('imagefile');
$mform->removeElement('imagealt');
}
// If the user isn't fully set up, let them know that they will be able to change
// their profile picture once their profile is complete.
if ($usernotfullysetup) {
$userpicturewarning = $mform->createElement('warning', 'userpicturewarning', 'notifymessage', get_string('newpictureusernotsetup'));
$enabledusernamefields = useredit_get_enabled_name_fields();
if ($mform->elementExists('moodle_additional_names')) {
$mform->insertElementBefore($userpicturewarning, 'moodle_additional_names');
} else if ($mform->elementExists('moodle_interests')) {
$mform->insertElementBefore($userpicturewarning, 'moodle_interests');
} else {
$mform->insertElementBefore($userpicturewarning, 'moodle_optional');
}
// This is expected to exist when the form is submitted.
$imagefile = $mform->createElement('hidden', 'imagefile');
$mform->insertElementBefore($imagefile, 'userpicturewarning');
}
// Next the customisable profile fields.
profile_definition($mform, $userid);