MDL-37459 admin: Fix for error on updating a locked checkbox
authorDamyon Wiese <damyon@moodle.com>
Wed, 12 Jun 2013 15:03:43 +0000 (23:03 +0800)
committerMarina Glancy <marina@moodle.com>
Thu, 13 Jun 2013 01:18:18 +0000 (11:18 +1000)
Changed the way apply_admin_locked_flags gets the current value for the field.

The old way was plain wrong (looking at getValue from the quickform element).

course/moodleform_mod.php

index 0e233d9..1cf3b8f 100644 (file)
@@ -893,6 +893,7 @@ abstract class moodleform_mod extends moodleform {
         $lockedicon = html_writer::tag('span',
                                        $OUTPUT->pix_icon('t/locked', get_string('locked', 'admin')),
                                        array('class' => 'action-icon'));
+        $isupdate = !empty($this->_cm);
 
         foreach ($settings as $name => $value) {
             if (strpos('_', $name) !== false) {
@@ -902,8 +903,12 @@ abstract class moodleform_mod extends moodleform {
                 $element = $mform->getElement($name);
                 $lockedsetting = $name . '_locked';
                 if (!empty($settings->$lockedsetting)) {
-                    $value = $mform->getElement($name)->getValue();
-                    $value = reset($value);
+                    // Always lock locked settings for new modules,
+                    // for updates, only lock them if the current value is the same as the default (or there is no current value).
+                    $value = $settings->$name;
+                    if ($isupdate && isset($this->current->$name)) {
+                        $value = $this->current->$name;
+                    }
                     if ($value == $settings->$name) {
                         $mform->setConstant($name, $settings->$name);
                         $element->setLabel($element->getLabel() . $lockedicon);