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

Proposal: API standard in Moodle that uses autoloading (hooks)

    Details

    • Testing Instructions:
      Hide

      Add db/hooks.php to some plugin with a callback for \core\hook\pre_delete_course
      Output something in this callback.
      Create and delete the course
      Make sure the output was printed

      Show
      Add db/hooks.php to some plugin with a callback for \core\hook\pre_delete_course Output something in this callback. Create and delete the course Make sure the output was printed
    • Affected Branches:
      MOODLE_26_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-44078-master

      Description

      At the moment Moodle has plenty of little APIs (consisting of one-two functions each) that require plugins to define PLUGINNAME_CALLBACKNAME() functions in their lib.php files.

      Examples:

      • xxx_print_recent_activity
      • xxx_get_recent_mod_activity
      • xxx_reset_course_form_definition
      • xxx_comment_display
      • xxx_grade_item_update
      • xxx_add_istance_hook
      • xxx_restore_group_member
      • xxx_restore_group_assignment
      • xxx_delete_instance
      • xxx_delete_course
      • xxx_supports
        ... (and so on, just grep by "component_callback" or "function_exists" )

      There are several problems with this approach:

      • bad documentation, hard to know about all various existing callbacks
      • easy to confuse the arguments because there is no interface
      • necessary to include all lib.php files (which are sometimes huge) to find handful of plugins implementing functions - SLOW!
      • limiting implementation to one plugin type because otherwise it's too expensive to look for callbacks

      Suggested approach that was discussed on backend meetings, especially with Petr Skoda is to use hooks and class autoloading.

      There is no goal to convert all existing APIs into the new format ASAP but will be nice to gradually do it, slowly deprecating old-style callbacks.

      There are at least two issues that would benefit from the agreement on standard:

      • MDL-43742 converting recent activity callbacks (atm we need to implement two very similar callbacks in each module)
      • MDL-24359 extending course reset callbacks to other plugin types (i.e. blocks)

      Forum post: https://moodle.org/mod/forum/discuss.php?d=254508

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                Dates

                • Created:
                  Updated:
                  Resolved: