Activity Module Plugin Hello World (like LABEL)

Activity Module Plugin Hello World (like LABEL)

by JJ Booth -
Number of replies: 1

Is there a simple tutorial anywhere for creating an Activity Module plugin?

I've followed the Block tutorial and found it perfect, except that the block appears on the left or right of the main course content.

I want to create my own plugin that I can add in the middle of a course page (or sub-page) that works almost exactly like the Label plugin (mod_label) but can display my custom work using PHP that I write.

I have been experimenting on and off for months and I'm getting nowhere.

Just some sort of "Hello World" plugin that does what I want would be awesome, but I simply can't find any information about it. Every forum post leads back to either the Block tutorial (again, been there, done that) or to the NEWMODULE page which has no good tutorial and is just loaded with technical information that is probably unneccessary.

And before you say it, I have tried cloning and modifying the Label plugin and I'm getting nowhere! I can figure out where the content is actually rendered to the screen, or where the content is even built from the database info.

Help please!

Average of ratings: -
In reply to JJ Booth

Re: Activity Module Plugin Hello World (like LABEL)

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

This is the line of code that outputs the content of the label to be added to the page:

https://github.com/moodle/moodle/blob/master/mod/label/lib.php#L144

Note that this data is cached, as label content is assumed not to change (unless the activity itself is edited). There are ways to output dynamic content into the course page, but I can't remember the exact code, off the top of my head.

Note also this line: 

https://github.com/moodle/moodle/blob/master/mod/label/lib.php#L188

That declares that there is no link to 'view' the label activity.