Skip to content

Commit

Permalink
MDL-51834 auth,profile: locks custom fields based on auth settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kwiliarty committed Oct 23, 2015
1 parent 91aaa24 commit b718906
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions user/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public function definition_after_data() {
// Disable fields that are locked by auth plugins.
$fields = get_user_fieldnames();
$authplugin = get_auth_plugin($user->auth);
$customfields = $authplugin->get_custom_user_profile_fields();
$fields = array_merge($fields, $customfields);
foreach ($fields as $field) {
if ($field === 'description') {
// Hard coded hack for description field. See MDL-37704 for details.
Expand All @@ -135,14 +137,15 @@ public function definition_after_data() {
if (!$mform->elementExists($formfield)) {
continue;
}
$value = $mform->getElementValue($formfield);
$configvariable = 'field_lock_' . $field;
if (isset($authplugin->config->{$configvariable})) {
if ($authplugin->config->{$configvariable} === 'locked') {
$mform->hardFreeze($formfield);
$mform->setConstant($formfield, $user->$field);
} else if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->$field != '') {
$mform->setConstant($formfield, $value);
} else if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $value != '') {
$mform->hardFreeze($formfield);
$mform->setConstant($formfield, $user->$field);
$mform->setConstant($formfield, $value);
}
}
}
Expand Down

0 comments on commit b718906

Please sign in to comment.