覆盖插件渲染器moodle
I have site running Moodle 2.9.3+ and i was trying to customize the renderer of one existing plugin, so i found this:
I added the following into the core_renderer.php of my theme
include_once($CFG->dirroot . "/course/format/topcoll/renderer.php");
but when i tried to do
class topcoll_local_renderer extends format_topcoll_renderer {
protected function section_header($section, $course, $onsectionpage, $sectionreturn = null) {
...
}
}
it runs, but it's not loading the modified function. Do I need to do anything else? the modified function is running with no issues when I alter the code directly into the plugin, but not like this. I would greatly appreciate any possible hint.
Thanks
我有运行Moodle 2.9.3+的网站,我试图自定义一个现有插件的渲染器,所以我 发现了这个: p>
我将以下内容添加到core_renderer.php中 我的主题 p>
include_once($ CFG-> dirroot。“/ course/format/topcoll/renderer.php");
但当我尝试 p>
class topcoll_local_renderer extends format_topcoll_renderer {
protected function section_header($ section,$ course,$ onsectionpage,$ sectionreturn = null){
...
}
}
code> pre>
它运行,但它没有加载修改后的函数。 我还需要做其他事吗? 当我将代码直接更改为插件时,修改后的函数运行时没有问题,但不是这样的。 我非常感谢任何可能的提示。 p>
谢谢 p>
div>
You need to do two things to get a theme renderer to override a core renderer:
- You need to edit the theme's config.php to add the line: $THEME->rendererfactory = 'theme_overridden_renderer_factory';
- You need to name your renderer class 'theme_NAMEOFTHEME_format_topcoll_renderer' (and extend 'format_topcoll_renderer', as you have done).
The theme_overridden_renderer_factory works by extending the process of instantiating a renderer to look for a class that matches the name 'theme_NAMEOFTHEME_NAMEOFRENDERER' - as long as that class exists, then it should be used (otherwise the original renderer is used).
See https://docs.moodle.org/dev/Overriding_a_renderer for more details.
Hmmm are you sure there isn't an error in the script inclusion? If you have error_reporting
off in your ini settings you won't see the E_WARNING
PHP might be raising. Set this to on, or use require_once()
instead. See the accepted response to this SO post for the differences: Difference between require, include and require_once?