Overriding overriden course_renderer

Overriding overriden course_renderer

by Edukacija.net mentor -
Number of replies: 2

Hello,

I have created a Fordson child theme and now trying to override course_renderer class with maintaining some of the functions already overriden in the Fordson theme.

Fordson theme has overriden core_course_renderer in the theme\fordson\classes\output\core\course_renderer.php and I am trying to override its course_renderer in the theme\fordsonupdated\classes\output\core\course_renderer.php.

I tried this:

class theme_fordsonupdated_course_renderer extends theme_fordson_course_renderer

and this:

class course_renderer extends \theme_fordson\output\core\course_renderer

but both times received an error:

Fatal error: Class 'theme_fordson\output\core\theme_fordson_course_renderer' not found in /usr/share/nginx/test.elearning.hr/theme/fordsonupdated/classes/output/core/course_renderer.php on line 46

I have tried several other versions, but without success. I suppose I am not using namespaces correctly, but currently I am stucked here, and would appreciate any help.

Thanks.

Average of ratings: -
In reply to Edukacija.net mentor

Re: Overriding overriden course_renderer

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
As the class name 'theme_fordsone_course_renderer' does not match the filename 'course_renderer.php', I suspect the automatic class loading is failing.

You could try manually calling require_once($CFG->dirroot.'/theme/fordson/classes/output/course_renderer.php') - that should fix the issue?
Average of ratings: Useful (1)
In reply to Davo Smith

Re: Overriding overriden course_renderer

by Edukacija.net mentor -
Thank you Davo.
Yes, this helped, although another issue was because of the conditional overriding in Fordson theme:
    
if ($PAGE->theme->settings->coursetilestyle < 10) {
    class course_renderer extends \core_course_renderer  {
So, if the settings didn't match the above condition, course_renderer wasn't overriden. Once I added the same condition and require_once like you suggested, everything worked ok.