title: Moodle 2.8 - How to set the default value of an advanced checkbox (advcheckbox) while using a checkbox_controller?
body: <p>I have tried following the advice for <a href="https://docs.moodle.org/dev/lib/formslib.php_add_checkbox_controller" rel="nofollow">using checkbox controllers in Moodle</a> in a moodle_form. However, the setDefault() function doesn't seem to work as expected. I am able to set default values without using the checkbox controller; when I add the latter, the original value (which sets all of the member checkboxes to checked or unchecked) seems to override anything I attempt set as the default later on.</p>
  
  <p>Here is the relevant code:</p>
  
  <pre><code>    foreach ($groups as $group) {
          $elname = 'linkedgroups[' . $group-&gt;id . ']';
          $mform-&gt;addElement('advcheckbox', $elname, $group-&gt;name, null, array('group' =&gt; 2));
      }
  
      $this-&gt;add_checkbox_controller(2, null, array('style' =&gt; 'font-weight: bold;'), 0);
      foreach ($groupsassignedids as $groupid) {
          $mform-&gt;setDefault('linkedgroups['. $groupid . ']', 1);
      }
  </code></pre>