General developer forum

overriding functions in /question/type/multichoice/renderer.php

 
6
overriding functions in /question/type/multichoice/renderer.php
 

Hi

under /question/type/multichoice/renderer.php there a public function called "formulation_and_controls"

I want to modify that function with my own code but in a way that won't cause my code to get overwritten the next time I upgrade moodle.

I have my own theme called "foresttheme" so if it can be done in the theme folder that's great, but doing it in the "local" folder is also great.

after reading this: https://docs.moodle.org/dev/Overriding_a_renderer#Overriding_a_component.27s_renderer


I've tried creating a file named "core_question_type_multichoice_renderer.php" under /themes/foresttheme/renderes/

with this:

require_once ($CFG->dirroot.'/question/type/multichoice/renderer.php');

abstract class theme_foresttheme_question_type_multichoice_renderer extends qtype_multichoice_renderer_base{

 public function formulation_and_controls(question_attempt $qa,

  question_display_options $options) {

 // mode code

 }

}


but it doesn't work, it doesn't get to my "formulation_and_controls" function.


I have moodle 3.1 installed.


 
Average of ratings: -
Picture of Darko Miletić
Re: overriding functions in /question/type/multichoice/renderer.php
Core developersParticularly helpful Moodlers

Why did you declare your class as abstract? Abstract classes can not be instantiated.

See class abstraction.

I've tried creating a file named "core_question_type_multichoice_renderer.php" under /themes/foresttheme/renderes/

Again, why? This is not what the document you linked states. The document states that you need to place any classes that override some renderers into your theme renderer.php file.





 
Average of ratings: -
6
Re: overriding functions in /question/type/multichoice/renderer.php
 

about the location of the class to override renderers:

in "/theme/foresttheme/renderers.php" i used this:
require_once('renderers/core_question_type_multichoice_renderer.php');

so I believe it's the same as putting the content of "core_question_type_multichoice_renderer.php" in /foresttheme/renderers.php
i see it's loading the content of "core_question_type_multichoice_renderer.php".
maybe I'm not using the right filename?

about the class name:
this is the class as it appears in "/question/type/multichoice/renderer.php:"

abstract class qtype_multichoice_renderer_base extends qtype_with_combined_feedback_renderer {


what should be my class name and what class should I be extending ?

this didn't work:
class theme_foresttheme_question_type_multichoice_renderer extends qtype_with_combined_feedback_renderer {

nor did this:
class theme_foresttheme_question_type_multichoice_renderer extends question_type_multichoice_renderer {


 
Average of ratings: -
Picture of Darko Miletić
Re: overriding functions in /question/type/multichoice/renderer.php
Core developersParticularly helpful Moodlers

Regarding misunderstanding what abstract means you should do some basic programming course.

This is what you need in your renderers.php

require_once($CFG->dirroot.'/question/type/rendererbase.php');
require_once($CFG->dirroot.'/question/type/multichoice/renderer.php');

class theme_clean_qtype_multichoice_single_renderer extends qtype_multichoice_single_renderer {

}

class theme_clean_qtype_multichoice_multi_renderer extends qtype_multichoice_multi_renderer {

}





 
Average of ratings: Useful (2)