MDL-71051 core_user: fix issues and address review issues
This commit is contained in:
committed by
Marina Glancy
parent
8974874018
commit
3bf770c801
@@ -231,9 +231,9 @@ if ($hassiteconfig
|
||||
|
||||
// Custom profile fields.
|
||||
$profilefields = profile_get_custom_fields();
|
||||
foreach ($profilefields as $key => $field) {
|
||||
// Only reasonable-length fields can be used as identity fields.
|
||||
if ($field->param2 > 255) {
|
||||
foreach ($profilefields as $field) {
|
||||
// Only reasonable-length text fields can be used as identity fields.
|
||||
if ($field->param2 > 255 || $field->datatype != 'text') {
|
||||
continue;
|
||||
}
|
||||
$fields['profile_field_' . $field->shortname] = $field->name . ' *';
|
||||
|
||||
@@ -44,7 +44,7 @@ class award_criteria_profile extends award_criteria {
|
||||
*
|
||||
*/
|
||||
public function get_options(&$mform) {
|
||||
global $CFG;
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->dirroot . '/user/profile/lib.php');
|
||||
|
||||
$none = true;
|
||||
@@ -93,13 +93,14 @@ class award_criteria_profile extends award_criteria {
|
||||
foreach ($cfields as $field) {
|
||||
if (!isset($currentcat) || $currentcat != $field->categoryid) {
|
||||
$currentcat = $field->categoryid;
|
||||
$mform->addElement('header', 'category_' . $currentcat, format_string($field->categoryname));
|
||||
$categoryname = $DB->get_field('user_info_category', 'name', ['id' => $field->categoryid]);
|
||||
$mform->addElement('header', 'category_' . $currentcat, format_string($categoryname));
|
||||
}
|
||||
$checked = false;
|
||||
if (in_array($field->id, $existing)) {
|
||||
$checked = true;
|
||||
}
|
||||
$this->config_options($mform, array('id' => $field->fieldid, 'checked' => $checked, 'name' => $field->name, 'error' => false));
|
||||
$this->config_options($mform, array('id' => $field->id, 'checked' => $checked, 'name' => $field->name, 'error' => false));
|
||||
$none = false;
|
||||
}
|
||||
}
|
||||
@@ -135,7 +136,9 @@ class award_criteria_profile extends award_criteria {
|
||||
foreach ($this->params as $p) {
|
||||
if (is_numeric($p['field'])) {
|
||||
$fields = profile_get_custom_fields();
|
||||
$str = $fields[$p['field']]->name ?? $p['field'];
|
||||
// Get formatted field name if such field exists.
|
||||
$str = isset($fields[$p['field']]->name) ?
|
||||
format_string($fields[$p['field']]->name) : null;
|
||||
} else {
|
||||
$str = \core_user\fields::get_display_name($p['field']);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ Feature: Select user identity fields
|
||||
| user1 | C1 | manager |
|
||||
| user2 | C1 | manager |
|
||||
|
||||
Scenario: The admin settings screen should show text custom fields (and let you choose them)
|
||||
Scenario: The admin settings screen should show text custom fields of certain length (and let you choose them)
|
||||
When I log in as "admin"
|
||||
And I navigate to "Users > Permissions > User policies" in site administration
|
||||
Then I should see "Speciality" in the "#admin-showuseridentity" "css_element"
|
||||
|
||||
@@ -122,14 +122,14 @@ class profile_field_form extends dynamic_form {
|
||||
$field = $this->get_field_record();
|
||||
|
||||
// Clean and prepare description for the editor.
|
||||
$field->description = clean_text($field->description, $field->descriptionformat);
|
||||
$field->description = array('text' => $field->description, 'format' => $field->descriptionformat, 'itemid' => 0);
|
||||
$description = clean_text($field->description, $field->descriptionformat);
|
||||
$field->description = ['text' => $description, 'format' => $field->descriptionformat, 'itemid' => 0];
|
||||
// Convert the data format for.
|
||||
if (is_array($this->editors())) {
|
||||
foreach ($this->editors() as $editor) {
|
||||
if (isset($field->$editor)) {
|
||||
$field->$editor = clean_text($field->$editor, $field->{$editor.'format'});
|
||||
$field->$editor = array('text' => $field->$editor, 'format' => $field->{$editor.'format'}, 'itemid' => 0);
|
||||
$editordesc = clean_text($field->$editor, $field->{$editor.'format'});
|
||||
$field->$editor = ['text' => $editordesc, 'format' => $field->{$editor.'format'}, 'itemid' => 0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,10 +488,8 @@ function profile_list_categories() {
|
||||
* Create or update a profile category
|
||||
*
|
||||
* @param stdClass $data
|
||||
* @throws coding_exception
|
||||
* @throws dml_exception
|
||||
*/
|
||||
function profile_save_category(stdClass $data) {
|
||||
function profile_save_category(stdClass $data): void {
|
||||
global $DB;
|
||||
|
||||
if (empty($data->id)) {
|
||||
|
||||
@@ -8,14 +8,16 @@ Feature: Social profile fields can not have a duplicate shortname.
|
||||
Scenario: Verify you can edit social profile fields.
|
||||
Given I log in as "admin"
|
||||
When I navigate to "Users > Accounts > User profile fields" in site administration
|
||||
And I set the field "datatype" to "Social"
|
||||
And I click on "Create a new profile field" "link"
|
||||
And I click on "Social" "link"
|
||||
And I set the following fields to these values:
|
||||
| Short name | yahoo |
|
||||
| Networktype | Yahoo ID |
|
||||
| Short name | yahoo |
|
||||
And I click on "Save changes" "button"
|
||||
And I set the field "datatype" to "Social"
|
||||
And I click on "Create a new profile field" "link"
|
||||
And I click on "Social" "link"
|
||||
And I set the following fields to these values:
|
||||
| Short name | yahoo |
|
||||
| Networktype | Yahoo ID |
|
||||
| Short name | yahoo |
|
||||
And I click on "Save changes" "button"
|
||||
Then I should see "This short name is already in use"
|
||||
|
||||
@@ -854,7 +854,7 @@ function profile_save_custom_fields($userid, $profilefields) {
|
||||
* current request for all fields so that it can be used quickly.
|
||||
*
|
||||
* @param string $shortname Shortname of custom profile field
|
||||
* @return stdClass Object with properties id, shortname, name, visible, datatype, categoryid, etc
|
||||
* @return stdClass|null Object with properties id, shortname, name, visible, datatype, categoryid, etc
|
||||
*/
|
||||
function profile_get_custom_field_data_by_shortname(string $shortname): ?stdClass {
|
||||
$cache = \cache::make_from_params(cache_store::MODE_REQUEST, 'core_profile', 'customfields',
|
||||
|
||||
Reference in New Issue
Block a user