/** * Define the form. */ public function definition() { global $CFG, $COURSE, $USER; $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'); } $editoroptions = $this->_customdata['editoroptions']; $filemanageroptions = $this->_customdata['filemanageroptions']; $user = $this->_customdata['user']; $userid = $user->id; if (empty($user->country)) { // We must unset the value here so $CFG->country can be used as default one. unset($user->country); } // Accessibility: "Required" is bad legend text. $strgeneral = get_string('general'); $strrequired = get_string('required'); // Add some extra hidden fields. $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'course', $COURSE->id); $mform->setType('course', PARAM_INT); // Print the required moodle fields first. $mform->addElement('header', 'moodle', $strgeneral); // Shared fields. useredit_shared_definition($mform, $editoroptions, $filemanageroptions, $user); // Extra settigs. 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); $this->add_action_buttons(false, get_string('updatemyprofile')); $this->set_data($user); }
/** * Test that the enabled fields are returned in the correct order. */ function test_useredit_get_enabled_name_fields() { global $CFG; // Back up config settings for restore later. $originalcfg = new stdClass(); $originalcfg->fullnamedisplay = $CFG->fullnamedisplay; $CFG->fullnamedisplay = 'language'; $expectedresult = array(); $this->assertEquals(useredit_get_enabled_name_fields(), $expectedresult); $CFG->fullnamedisplay = 'firstname lastname firstnamephonetic'; $expectedresult = array(19 => 'firstnamephonetic'); $this->assertEquals(useredit_get_enabled_name_fields(), $expectedresult); $CFG->fullnamedisplay = 'firstnamephonetic, lastname lastnamephonetic (alternatename)'; $expectedresult = array('firstnamephonetic', 28 => 'lastnamephonetic', 46 => 'alternatename'); $this->assertEquals(useredit_get_enabled_name_fields(), $expectedresult); $CFG->fullnamedisplay = 'firstnamephonetic lastnamephonetic alternatename middlename'; $expectedresult = array('firstnamephonetic', 18 => 'lastnamephonetic', 35 => 'alternatename', 49 => 'middlename'); $this->assertEquals(useredit_get_enabled_name_fields(), $expectedresult); // Tidy up after we finish testing. $CFG->fullnamedisplay = $originalcfg->fullnamedisplay; }
/** * Gets user name fields not enabled from the setting fullnamedisplay. * * @param array $enabledadditionalusernames Current enabled additional user name fields. * @return array Disabled user name fields. */ function useredit_get_disabled_name_fields($enabledadditionalusernames = null) { // If we don't have enabled additional user name information then go and fetch it (try to avoid). if (!isset($enabledadditionalusernames)) { $enabledadditionalusernames = useredit_get_enabled_name_fields(); } // These are the additional fields that are not currently enabled. $nonusednamefields = array_diff(get_all_user_name_fields(), array_merge(array('firstname', 'lastname'), $enabledadditionalusernames)); return $nonusednamefields; }