Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-66884

If course completion is enabled, you can't disable standard module elements in custom activity module

XMLWordPrintable

    • MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_38_STABLE
    • MDL-66884_master
    • Hide

      In order to test it, we'll need to modify Moodle code. Also, I've tested this with a custom activity module of mine, but we'll be testing with a activity module that isn't using the completion API from Moodle core, in this case, mod_label.

      1. Create a course and enable completion in it.
      2. Create a label within the course.
      3. Enrol a teacher in the course.
      4. Log in with the teacher enroled in the course in the previous step.
      5. Go to the file "/mod/label/mod_form.php" and comment the line that says "$this->standard_coursemodule_elements();"
      6. With the teacher user, try to edit the label, it will promp a Moodle Exception
      Show
      In order to test it, we'll need to modify Moodle code. Also, I've tested this with a custom activity module of mine, but we'll be testing with a activity module that isn't using the completion API from Moodle core, in this case, mod_label. Create a course and enable completion in it. Create a label within the course. Enrol a teacher in the course. Log in with the teacher enroled in the course in the previous step. Go to the file "/mod/label/mod_form.php" and comment the line that says "$this->standard_coursemodule_elements();" With the teacher user, try to edit the label, it will promp a Moodle Exception

      When creating a custom activity module, a "mod_form.php" file is required, which will be used as form to create or edit instances of said activity module. In this form, just before adding the submit and cancel buttons, there is the next function call:

      $this->standard_coursemodule_elements()

       Which, as its own name says, loads the standard module elements (settings).

      Now, for the problem that i've stumbled upon to. It seems like, if you want to have your activity module form without standard mod options and delete that line while having the course completion enabled, it will promp a Moodle exception (see screenshot ahead).

      Following the error trace, I've run into the following chunk of code (on /course/moodleform_mod.php, function "definition_after_data"):

      $mform->getElement('completionunlocked')->setValue(1)
      

      It does this twice: when nobody has completed the module yet or well when somebody has pressed the button to unlock the completion.

      This could be easily solved surrounding those two lines with a statement that checks if "completionunlocked" field exists in the form.

      I've already tried it several activity modules and it doesn't seems to have any weird behaviour, so I'll try to pull request it.

            Unassigned Unassigned
            Royer Yerai Rodríguez
            Votes:
            5 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.