Thanks Gareth, with a little more time I've worked out how to do it. I'll try and explain for others who may be interested.
I want to display custom code for some activities on the course page rather than just a link to the activity. This will allow students to see other information about an activity directly on the course page without having to click on it. I have created some custom activities where this is useful, such as one that shows a certificate on the course page when another activity is complete or the course is complete.
Firstly I've made a copy of the Topics course format and renamed all the references to Topic as myformat.
The function that displays a single course activity is 'course_section_cm' a method of the class 'core_course_renderer' which is defined in '/course/renderer.php'. I therefore need to override this function with my own code.
The Topics format already has its own renderer class defined in 'renderer.php'. In my instance this is now called 'format_myformat_renderer' and it extends the 'format_section_renderer_base' class.
A course format may have one custom renderer and it must take be named format_{formatname}_renderer. Because the renderer is already present I can't just create another as I had tried in the post above as Moodle won't recognise it.
I can't just put my override 'course_section_cm' function in this class as it is extending the class 'format_section_renderer_base' instead of 'core_course_renderer' where the original 'course_section_cm' resides. The class cannot extend two different classes so I have to instantiate a new class to extend 'core_course_renderer'. This done by adding a line of code to the constructor class which is already being overridden in the format renderer. I'll call my new class format_myformat_course_renderer although I could call it anything.
public function __construct(moodle_page $page, $target) {
parent::__construct($page, $target);
//this line creates a new class that can extend the 'core_course_renderer'
$this->courserenderer = new format_myformat_course_renderer($page, $target);
// Since format_bish_renderer::section_edit_controls() only displays the 'Set current section' control when editing mode is on
// we need to be sure that the link 'Turn editing mode on' is available for a user who does not have any other managing capability.
$page->set_other_editing_capability('moodle/course:setcurrentsection');
}
Now I have a class that I can use to override the functions in the 'core_course_renderer' and it will load when the course format loads.
Finally in 'renderer.php' I define the new class and the function I want to override. Note. You must also include the file where the renderer is defined.
require_once($CFG->dirroot.'/course/renderer.php');
class format_myformat_course_renderer extends core_course_renderer{
public function course_section_cm($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = array()) {
....my custom code....
}
}
All I need to do now is insert my custom code. I this instance all I'll do is use a switch statement to identify the type of mod using $mod->modname and display content accordingly.
Job done. I hope that makes sense, if you want to know anything else just ask.