mirror of
https://github.com/moodle/moodle.git
synced 2025-08-02 07:39:54 +02:00
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:
parent
c9af13123d
commit
c86500a4b7
2 changed files with 21 additions and 1 deletions
|
@ -1263,6 +1263,7 @@ Cheers from the \'{$a->sitename}\' administrator,
|
||||||
{$a->signoff}';
|
{$a->signoff}';
|
||||||
$string['newpicture'] = 'New picture';
|
$string['newpicture'] = 'New picture';
|
||||||
$string['newpicture_help'] = 'To add a new picture, browse and select an image (in JPG or PNG format) then click "Update profile". The image will be cropped to a square and resized to 100x100 pixels.';
|
$string['newpicture_help'] = 'To add a new picture, browse and select an image (in JPG or PNG format) then click "Update profile". The image will be cropped to a square and resized to 100x100 pixels.';
|
||||||
|
$string['newpictureusernotsetup'] = 'A profile picture can only be added once all required profile information has been saved.';
|
||||||
$string['newsectionname'] = 'New name for section {$a}';
|
$string['newsectionname'] = 'New name for section {$a}';
|
||||||
$string['newsitem'] = 'news item';
|
$string['newsitem'] = 'news item';
|
||||||
$string['newsitems'] = 'news items';
|
$string['newsitems'] = 'news items';
|
||||||
|
|
|
@ -45,6 +45,7 @@ class user_edit_form extends moodleform {
|
||||||
$mform = $this->_form;
|
$mform = $this->_form;
|
||||||
$editoroptions = null;
|
$editoroptions = null;
|
||||||
$filemanageroptions = null;
|
$filemanageroptions = null;
|
||||||
|
$usernotfullysetup = user_not_fully_set_up($USER);
|
||||||
|
|
||||||
if (!is_array($this->_customdata)) {
|
if (!is_array($this->_customdata)) {
|
||||||
throw new coding_exception('invalid custom data for user_edit_form');
|
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);
|
useredit_shared_definition($mform, $editoroptions, $filemanageroptions, $user);
|
||||||
|
|
||||||
// Extra settigs.
|
// Extra settigs.
|
||||||
if (!empty($CFG->disableuserimages)) {
|
if (!empty($CFG->disableuserimages) || $usernotfullysetup) {
|
||||||
$mform->removeElement('deletepicture');
|
$mform->removeElement('deletepicture');
|
||||||
$mform->removeElement('imagefile');
|
$mform->removeElement('imagefile');
|
||||||
$mform->removeElement('imagealt');
|
$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.
|
// Next the customisable profile fields.
|
||||||
profile_definition($mform, $userid);
|
profile_definition($mform, $userid);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue