Plugin repository context vs Activity modules

Plugin repository context vs Activity modules

by Gabriele Bernardello -
Number of replies: 1

I need to develop a Moodle (4.0) repository plugin that allows searching and downloading content from an external repository.

One of the constraints I have is the need to communicate to the external repository's APIs the required format for download. Let me explain further: on the Moodle side, a course is created, I add a topic, and within it, I want to upload an SCORM or IMS, etc. I choose the correct module and, within the selected module's page, I open the file picker. My repository plugin is displayed in Moodle's file picker. I perform a search on the external repository and decide to download a material, but this material must be packaged as SCORM 1.2, or IMS, or downloaded as a single file (e.g., a PDF, an image). However, to have the correct package type, I need to know if I am inside an SCORM module, or IMS, etc. At the moment, I cannot get this information; the context defined in the constructor has contextlevel = CONTEXT_COURSE and does not contain (or at least I cannot find) information related to the selected module.

With "module," I mean the Activity modules (e.g., "IMS content package" or "SCORM package"), although I am not sure if I have used the correct term.

Average of ratings: -
In reply to Gabriele Bernardello

Re: Plugin repository context vs Activity modules

by Renaat Debleu -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
You are right, the moment you edit an activity, you get the course context and not the module context. I struggled with the same problem when creating the repository_s3bucket plugin. First I thought it had something to do with copying all files to the user context when you start editing, but the reason is more simple: there are no repository instances in a module context. You can create them globally, in a category or in a course, but not inside a module.

You could add an extra module context parameter to your constructor, but this will be tricky when you create a new module (I doubt when the module context is created, when creating a new module or when saving the new module).