/** * This function renders the form elements when adding a customcert element. * * @param mod_customcert_edit_element_form $mform the edit_form instance */ public function render_form_elements($mform) { // Get the user profile fields. $userfields = array('firstname' => get_user_field_name('firstname'), 'lastname' => get_user_field_name('lastname'), 'email' => get_user_field_name('email'), 'city' => get_user_field_name('city'), 'country' => get_user_field_name('country'), 'url' => get_user_field_name('url'), 'icq' => get_user_field_name('icq'), 'skype' => get_user_field_name('skype'), 'aim' => get_user_field_name('aim'), 'yahoo' => get_user_field_name('yahoo'), 'msn' => get_user_field_name('msn'), 'idnumber' => get_user_field_name('idnumber'), 'institution' => get_user_field_name('institution'), 'department' => get_user_field_name('department'), 'phone1' => get_user_field_name('phone1'), 'phone2' => get_user_field_name('phone2'), 'address' => get_user_field_name('address')); // Get the user custom fields. $arrcustomfields = \availability_profile\condition::get_custom_profile_fields(); $customfields = array(); foreach ($arrcustomfields as $key => $customfield) { $customfields[$customfield->id] = $key; } // Combine the two. $fields = $userfields + $customfields; core_collator::asort($fields); // Create the select box where the user field is selected. $mform->addElement('select', 'userfield', get_string('userfield', 'customcertelement_userfield'), $fields); $mform->setType('userfield', PARAM_ALPHANUM); $mform->addHelpButton('userfield', 'userfield', 'customcertelement_userfield'); parent::render_form_elements($mform); }
/** * Tests what happens with custom fields that are text areas. These should * not be offered in the menu because their data is not included in user * object */ public function test_custom_textarea_field() { global $USER, $SITE, $DB; $this->setAdminUser(); $info = new \core_availability\mock_info(); // Add custom textarea type. $DB->insert_record('user_info_field', array('shortname' => 'longtext', 'name' => 'Long text', 'categoryid' => 1, 'datatype' => 'textarea')); $customfield = $DB->get_record('user_info_field', array('shortname' => 'longtext')); // The list of fields should include the text field added in setUp(), // but should not include the textarea field added just now. $fields = condition::get_custom_profile_fields(); $this->assertEquals(array('frogtype'), array_keys($fields)); }