General developer forum

Can the class qbehaviour_renderer be overriden in theme?

 
Picture of Lea Cohen
Re: Can the class qbehaviour_renderer be overriden in theme?
 
Thank you very much for your detailed reply, I really appreciate it. I actually did see that the base calls was ovrriden by the various behaviours but it didn't occur to me that that means I should be extending them. Wasn't thinking things through, unfortunately.

I tried now, however, to override one of the subclassses used in our instance - adaptivenopenalty:
require_once($CFG->dirroot . '/question/behaviour/adaptivenopenalty/renderer.php'); 
class theme_mytheme_qbehaviour_adaptivenopenalty_renderer extends \qbehaviour_adaptivenopenalty_renderer {
}
But that still doesn't work (the function isn't called), and on some pages it even gives me an error about its parent class (qbehaviour_adaptivenopenalty_renderer extentds qbehaviour_adaptive_renderer) and that's weird since I didn't touch any other file other that my core_renderer:

( ! ) Fatal error: Class 'qbehaviour_renderer' not found in /html/aviv2017/question/behaviour/adaptive/renderer.php on line

But I don't want to burden you with these problem since I think this isn't the path to go in since, even if it worked, I'd have to extend all subclasses and that's too tedious and error prone, and also doesn't scale if more subclasses are added.

Since the change I want is to add a class to the submit button,  I see my options as follows:
  1. Make my change in core (in the original qbehaviour_renderer class) and take care of upgrade clashes, if occur, using git.
  2. Make my change using JavaScript.
  3. Adapt the CSS to conform to the current classes.
Non of them is ideal, but they'll work.

Regarding patch:  I'd love to write a patch but unfortunately I'm not familiar enough with the Moodle code to do so.
 
Average of ratings: -