General developer forum

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

 
Picture of Richard Jones
Can a text filter find out which module it is in?
 

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: -
Davo
Re: Can a text filter find out which module it is in?
Core developersParticularly helpful MoodlersPlugin 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 (4)
Picture of Richard Jones
Re: Can a text filter find out which module it is in?
 

Perfect, thanks Davo.

 
Average of ratings: -