General developer forum

Issue extending core_renderer to override outputrenderers methods

 
Picture of Nathan Hunt
Issue extending core_renderer to override outputrenderers methods
 

There are a few Moodle renders I would like to override so that I can change the output/html for the custom theme I'm making.

There file is in the moodle root lib/outputrenderers.php

I did some searching around and came across https://docs.moodle.org/dev/Overriding_a_renderer#Our_first_renderer so I tried to follow this. I created a file in the root of my theme called renderers.php with the class:

class theme_mythemename_core_renderer extends core_renderer

And, for example on one of the methods I wanted to override, I copied the user_menu method and placed it within the class.

However, when I go to my moodle site I now get the error "Exception - Call to undefined method theme_mythemename_core_renderer::region_main_settings_menu()". The only method I have defined is the user_menu one, which is extending the core_renderer so I shouldn't imagine I have to copy every method over into my new class?

I must note I am using Moodle 3.3, and the docs in that link are a bit confusing as it states 2.9+ should use templates, but the methods I'm wanting to override are still using html_writer. So don't know if I'm going about it the right way or not?

I also have the following setting in my theme's config.php file:

$THEME->rendererfactory = 'theme_overridden_renderer_factory';

 
Average of ratings: Useful (1)
Picture of Tobias Marx
Re: Issue extending core_renderer to override outputrenderers methods
 

No one?

I've got a similar problem (though in my case, the overridden functions are just ignored... sad ).

Can anyone explain how overriding an output render in Moodle 3.3 works, please?

Regards

Tobias

 
Average of ratings: -
Picture of Dale Davies
Re: Issue extending core_renderer to override outputrenderers methods
Particularly helpful Moodlers

Not sure if you'd just pasted it as an example, but you would need to update the mythemename part of that line with your own theme name..

class theme_mythemename_core_renderer extends core_renderer

 
Average of ratings: -
Picture of Tobias Marx
Re: Issue extending core_renderer to override outputrenderers methods
 

I can't speak for the OP, but in my case I've used the theme's name:


<?php

defined('MOODLE_INTERNAL') || die();

class theme_boost_core_renderer extends core_renderer {

}

include_once($CFG->dirroot . "/course/renderer.php");

class theme_boost_core_course_renderer extends core_course_renderer {

   /**
    * Renders HTML to display particular course category - list of it's subcategories and courses
    *
    * Invoked from /course/index.php
    *
    * @param int|stdClass|coursecat $category
    */
   public function course_category($category) {
       global $CFG;
       require_once($CFG->libdir. '/coursecatlib.php');
       $coursecat = coursecat::get(is_object($category) ? $category->id : $category);
       $site = get_site();
       $output = '';

</snip>

 
Average of ratings: -