renderer override not working

renderer override not working

by Doug Bott -
Number of replies: 8

I have overrides to the core_renderer on the same page working correctly but this code does not work..why? (the titles of the course page sections should all turn to "hello")

require_once($CFG->dirroot.'/course/format/renderer.php');
abstract class theme_mytheme_format_section_renderer_base extends format_section_renderer_base {
    public function section_header($section, $course, $onsectionpage, $sectionreturn=0) {
        global $PAGE;
        return 'hello';
    }
}

Average of ratings: -
In reply to Doug Bott

Re: renderer override not working

by Darko Miletić -

Are you sure your class should be abstract?

In reply to Darko Miletić

Re: renderer override not working

by Doug Bott -

if only because the source class is

abstract class format_section_renderer_base extends plugin_renderer_base {

    abstract protected function start_section_list();
    abstract protected function end_section_list();
    abstract protected function page_title();
.
.
etc
.
.
protected function section_header($section, $course, $onsectionpage, $sectionreturn=0) {
.
.
}
.
.
}

but I have also tried this code:

class theme_mytheme_format_section_renderer_base extends format_section_renderer_base {
    public function start_section_list(){return 'hello';}
    public function end_section_list(){return 'hello';}
    public function page_title(){return 'hello';}
    public function section_header($section, $course, $onsectionpage, $sectionreturn=0) {
        global $PAGE;
        return 'hello';
    }
}
In reply to Doug Bott

Re: renderer override not working

by Darko Miletić -

The base class is marked abstract because it is expected of implementer to provide methods marked as abstract. Than derived class is no longer abstract and should not be marked as such.

As for not working, you did try things outlined in this page?http://docs.moodle.org/dev/Overriding_a_renderer

In reply to Darko Miletić

Re: renderer override not working

by Doug Bott -

not much to do.

1. $THEME->rendererfactory = 'theme_overridden_renderer_factory'; is in config (in fact I have a  core_renderer override on the same file running well)

2. I included the file where the class is and

3. I believe I followed the naming conventions correctly.

Obviously I am missing something crucial but I cant figure out what it is....

 

In reply to Doug Bott

Re: renderer override not working

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

think (and you'd have to check), that none of the course formats use that renderer directly, but use derived classes based on that renderer.

thinktherefore, that what you are doing will only work if you override the actual class that is used by the course format and not the abstract base class (I have a half-memory of this coming up before in discussion).

Average of ratings: Useful (1)
In reply to Davo Smith

Re: renderer override not working

by Doug Bott -

Great! that works!!

that class is extended by format_topics_renderer

so I changed:

class theme_mytheme_format_section_renderer_base extends format_section_renderer_base {

to

class theme_mytheme_format_topics_renderer extends format_section_renderer_base{

interestingly I did not change the second argument (after "extends") by mistake but it worked!

In reply to Doug Bott

Re: renderer override not working

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

I'd be surprised if there weren't at least some issues with extending 'base' instead of the 'topics' renderer. To be on the safe side I'd still correct it (are there no warnings produced when you set debugging to 'developer'?).

In reply to Doug Bott

Re: renderer override not working

by John Lu -

The proper way to do it is to create a new folder (plugin) inside course/format/{yourpluginname} and use this custom course format by going to "Site Admin -> Plugins -> Course format -> Manage course formats" and set your {yourpluginname} as default.