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

mod_chooser dialog contains blank radio button options that cause an error when selected when activities improperly define _get_types() lib function

    Details

    • Database:
      MySQL
    • Testing Instructions:
      Hide
      • Open a course page, turn editing on
        • Confirm that the Activity chooser appears correctly - all modules appear
      • Switch of the Activity chooser
        • ensure that the dropdowns also appear correctly - all modules appear
      • Modify mod/choice/lib.php and add:

        function choice_get_types() {
            return array();
        }

      • Refresh the page
        • Confirm both dropdowns and the Activity chooser appear correctly but are now missing the 'Choice' module
        • Confirm that a debugging message telling you that the module definition is incorrect was shown
      • Edit mod/choice/lib.php again and update the function:

        function choice_get_types() {
            return null;
        }

      • Refresh the page
        • Confirm both dropdowns and the Activity chooser appear correctly but are now missing the 'Choice' module
        • Confirm that a debugging message telling you that the module definition is incorrect was shown
      Show
      Open a course page, turn editing on Confirm that the Activity chooser appears correctly - all modules appear Switch of the Activity chooser ensure that the dropdowns also appear correctly - all modules appear Modify mod/choice/lib.php and add: function choice_get_types() { return array(); } Refresh the page Confirm both dropdowns and the Activity chooser appear correctly but are now missing the 'Choice' module Confirm that a debugging message telling you that the module definition is incorrect was shown Edit mod/choice/lib.php again and update the function: function choice_get_types() { return null; } Refresh the page Confirm both dropdowns and the Activity chooser appear correctly but are now missing the 'Choice' module Confirm that a debugging message telling you that the module definition is incorrect was shown
    • Affected Branches:
      MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE
    • Pull Master Branch:

      Description

      If an activity defines a

      {modname}_get_types() lib function when the the activity does not have sub-types, the mod_chooser dialog will contain a blank radio button option that causes an error when selected and the "Add" button is clicked. The browser is directed to /course/jumpto.php without any parameters and the error "Error occurred" is displayed.

      The problem is with activity modules that define a {modname}

      _get_types() lib function and then return something other than an non-empty array. We have found that some 3rd party plugins define the function and return an empty array which triggers this bug. Ideally, plugins would not define this function, but I think that the calling function should better test the return value of the function. The calling function is in course/lib.php: get_module_metadata().

      I've attached a proposed fix that checks that what is returned from the function is a non-empty array. From what we've experienced this prevents the bug.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  11/Mar/13