From 3391ec00f0f889754c5d848e84f68865b7167067 Mon Sep 17 00:00:00 2001 From: Kevin Wiliarty Date: Mon, 19 Oct 2015 14:27:06 -0400 Subject: [PATCH] MDL-51834 auth,profile: locks custom fields based on auth settings --- user/edit_form.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/user/edit_form.php b/user/edit_form.php index 65e86076d89..da9e1c51119 100644 --- a/user/edit_form.php +++ b/user/edit_form.php @@ -125,6 +125,8 @@ class user_edit_form extends moodleform { // 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. @@ -135,14 +137,15 @@ class user_edit_form extends moodleform { 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); } } }