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

Provide standardised way for modules to indicate their support for Moodle features

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: Libraries
    • Labels:
      None
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE

      Description

      It would be nice to have a standardised way to indicate whether modules support certain features. At the moment, generally this is done by checking whether a function exists, which is not a great way to do it (and, for new module developers, can be prone to error).

      I threw some code together for the attached patch - this patch is for 1.9 just because, obviously there is no intention this would ever go into 1.9, also I'm not sure about the sketchy exception usage. So I'm not really expecting this would be checked into anything as-is, but if you think it's a good idea, I can put it into 2.0 later as part of the completion-tracking (conditional activities) work.

      Basically you call

      plugin_supports('mod','quiz',FEATURE_COMPLETION_TRACKS_VIEWS)

      then that opens quiz/lib.php and calls

      quiz_supports(FEATURE_COMPLETION_TRACKS_VIEWS)

      which can then return true or false. (Some features might be defined to have values instead so could also return something other than plain true.)

      If the function doesn't exist [legacy support] it returns false.

      We could also add extra legacy support if features are added eg FEATURE_CRON that could be checked the 'old' way without having to change modules, I have indicated where this would go inside the plugin_supports code.

      If it was decided to make modules entirely OOP for 2.0 then this approach would not be appropriate and we would probably be better off using interfaces or something.

        Attachments

          Activity

            People

            Assignee:
            skodak Petr Skoda
            Reporter:
            quen Sam Marshall
            Participants:
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              24/Nov/10