Can a text filter find out which module it is in?

Can a text filter find out which module it is in?

by Richard Jones -
Number of replies: 2
Picture of Plugin developers Picture of Testers

The filter can do this:

// Check our context and get the course id
  $coursectx = $this->context->get_course_context(false);
  $courseid = $coursectx->instanceid;

Which is fine.  However, I can't seem to find a way of telling if the filter is inside a module such as a lesson or a wiki and what it's id might be.

Once the filter has done it's job, I would like to get back to the module rather than the course, if possible.

Thanks if you can help.

Average of ratings: -
In reply to Richard Jones

Re: Can a text filter find out which module it is in?

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

You can always find out what activity you are within by using the $PAGE global:

global $PAGE;
if ($PAGE->cm) {
    if ($PAGE->cm->modname == 'wiki') {
        // Do something if we are on a 'wiki' page.
    }
}

Take a look at the moodle_page definition in lib/pagelib.php to see what else is available in $PAGE and cm_info in lib/modinfolib.php to see what else is available in $PAGE->cm

Average of ratings: Useful (5)