MDL-16839 forms: workaround for problematic hard frozen values; merged from MOODLE_19_STABLE

This commit is contained in:
skodak 2008-10-13 19:39:27 +00:00
parent a84ce52ecf
commit cc44433620
4 changed files with 24 additions and 6 deletions

View File

@ -82,6 +82,7 @@ class course_edit_form extends moodleform {
$mform->setType('fullname', PARAM_MULTILANG);
if ($course and !has_capability('moodle/course:changefullname', $coursecontext)) {
$mform->hardFreeze('fullname');
$mform->setConstant('fullname', $course->fullname);
}
$mform->addElement('text','shortname', get_string('shortname'),'maxlength="100" size="20"');
@ -91,6 +92,7 @@ class course_edit_form extends moodleform {
$mform->setType('shortname', PARAM_MULTILANG);
if ($course and !has_capability('moodle/course:changeshortname', $coursecontext)) {
$mform->hardFreeze('shortname');
$mform->setConstant('shortname', $course->shortname);
}
$mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100" size="10"');
@ -98,6 +100,7 @@ class course_edit_form extends moodleform {
$mform->setType('idnumber', PARAM_RAW);
if ($course and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
$mform->hardFreeze('idnumber');
$mform->setConstants('idnumber', $course->idnumber);
}
$mform->addElement('htmleditor','summary', get_string('summary'), array('rows'=> '10', 'cols'=>'65'));

View File

@ -1235,6 +1235,19 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
}
}
/**
* Set constant value not overriden by _POST or _GET
* note: this does not work for complex names with [] :-(
* @param string $elname name of element
* @param mixed $value
* @return void
*/
function setConstant($elname, $value) {
$this->_constantValues = HTML_QuickForm::arrayMerge($this->_constantValues, array($elname=>$value));
$element =& $this->getElement($elname);
$element->onQuickFormEvent('updateValue', null, $this);
}
function exportValues($elementList = null){
$unfiltered = array();
if (null === $elementList) {
@ -1645,8 +1658,8 @@ function validate_' . $this->_formName . '(frm) {
/**
* Displays elements without HTML input tags.
* This method is different to freeze() in that it makes sure no hidden
* elements are included in the form. And a 'hardFrozen' element's submitted value is
* ignored.
* elements are included in the form.
* Note: If you want to make sure the submitted value is ignored, please use setDefaults().
*
* This function also removes all previously defined rules.
*

View File

@ -74,7 +74,6 @@ class user_edit_form extends moodleform {
/// disable fields that are locked by auth plugins
$fields = get_user_fieldnames();
$freezefields = array();
$authplugin = get_auth_plugin($user->auth);
foreach ($fields as $field) {
if (!$mform->elementExists($field)) {
@ -83,13 +82,15 @@ class user_edit_form extends moodleform {
$configvariable = 'field_lock_' . $field;
if (isset($authplugin->config->{$configvariable})) {
if ($authplugin->config->{$configvariable} === 'locked') {
$freezefields[] = $field;
$mform->hardFreeze($field);
$mform->setConstant($field, $user->$field);
} else if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->$field != '') {
$freezefields[] = $field;
$mform->hardFreeze($field);
$mform->setConstant($field, $user->$field);
}
}
}
$mform->hardFreeze($freezefields);
}
/// Next the customisable profile fields

View File

@ -141,6 +141,7 @@ class profile_field_base {
function edit_field_set_locked(&$mform) {
if ($this->is_locked() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
$mform->hardFreeze($this->inputname);
$mform->setConstant($this->inputname, $this->data);
}
}