Custom activity plugin - how to add html content to course page instead of just name and description?

Custom activity plugin - how to add html content to course page instead of just name and description?

by Steve Ulczak -
Number of replies: 3

Hello,

I'm working on a custom Activity module that lets people sign up for live meeting sessions in Adobe Connect. I know there are several plugins out there that do this, but none of them seem to quite meet our very specific needs, so I'm working on my own.

I'm very new to Moodle development, but I do have a basic plugin working from a modified version of the NEWMODULE starter.

I've been successful in using the Connect API to display a selection of meeting dates from Connect in the View tab of my Moodle activity plugin.

So here's my question: I'd rather have the view.php content display directly on the course page to reduce the number of clicks the user must take to see the meeting registration options, since this activity is basically the only thing in that Topic section (kind of like how the Label activity works, where it doesn't create a second page that the user has to click into).

I've attached a screenshot that hopefully helps to illustrate what I'm asking.

It seemed like index.php might be the place to do this, so I tried echoing out some 'HELLO WORLD' statements, but nothing seems to have any impact.

I know this is a very basic question - but I've been all through the documentation and can't quite seem to find the right file to edit. Many thanks if someone can point me in the right direction!

Attachment Pasted_Image_3_10_17__12_44_PM.jpg
Average of ratings: -
In reply to Steve Ulczak

Re: Custom activity plugin - how to add html content to course page instead of just name and description?

by Murilo Timo Neto -

I would love to do that too.
Display an activity directly on the course page.
I hope soon I can contribute, your code is in github?

In reply to Steve Ulczak

Re: Custom activity plugin - how to add html content to course page instead of just name and description?

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

What you're talking about is probably more complicated than it seems.  A Label is really a module which only has a "Description" field - all modules have this field which can be optionally displayed on the course page.

The main problem with doing what you're suggesting is that what's displayed on the view page and how is completely up to the plugin, so there's no way of calling a standard function to get that output for the course page.

Another issue (probably the reason this isn't already possible) is that allowing plugins to do this could create a lot of clutter and inconsistency on the course page.  We've found that users prefer to have the course broken up into separate pages with a specific focus, rather than having lots of information crammed on one page.

One way something like this might be possible would be to have custom course format, which looks for a specially-named function in each plugin's renderer and uses that to generate the output for the course page.  However, this would rely on you editing each activity module you need to support to add this function.

In reply to Steve Ulczak

Re: Custom activity plugin - how to add html content to course page instead of just name and description?

by Christos Savva -

I wanted to do something similar so what I did was the following:


In the file lib.php I implemented the function 

cm_info_view(cm_info $cm)

And used the following property:

$cm->set_after_link();
So basically I have something like

function mod_awesomeplugin_cm_info_view(cm_info $cm) {
   ...
   logic stuff here
   ...
   //when I want to print below the activity name use
   $cm->set_after_link('Your HTML content here');
   
}

To be honest my implementation does not have any interaction, it just created a dynamic 'description' for the user. I don't know how efficient this is but it works.