覆盖插件渲染器moodle [英] Overriding plugin renderer moodle

查看:78
本文介绍了覆盖插件渲染器moodle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行 Moodle 2.9.3+ 的站点,我试图自定义一个现有插件的渲染器,所以我发现了这个:

如何覆盖一个渲染器,使得被覆盖的渲染器的功能也保持可用?

我在主题的 core_renderer.php 中添加了以下内容

<块引用>

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

但是当我尝试这样做时

class topcoll_local_renderer extends format_topcoll_renderer {受保护的函数 section_header($section, $course, $onsectionpage, $sectionreturn = null) {...}}

它运行了,但没有加载修改后的函数.我还需要做什么吗?当我将代码直接更改到插件中时,修改后的函数运行没有问题,但不是这样.我将不胜感激任何可能的提示.

谢谢

解决方案

你需要做两件事才能让主题渲染器覆盖核心渲染器:

  1. 您需要编辑主题的 config.php 以添加以下行:$THEME->rendererfactory = 'theme_overridden_​​renderer_factory';
  2. 您需要将渲染器类命名为theme_NAMEOFHEME_format_topcoll_renderer"(并像您所做的那样扩展format_topcoll_renderer").

theme_overridden_​​renderer_factory 的工作原理是扩展实例化渲染器的过程,以查找与名称theme_NAMEOFTHEME_NAMEOFRENDERER"匹配的类 - 只要该类存在,就应该使用它(否则使用原始渲染器).

请参阅 https://docs.moodle.org/dev/Overriding_a_renderer 了解更多详情.

I have site running Moodle 2.9.3+ and i was trying to customize the renderer of one existing plugin, so i found this:

How to override a renderer such that the functionality of the overridden renderer also remains available?

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

解决方案

You need to do two things to get a theme renderer to override a core renderer:

  1. You need to edit the theme's config.php to add the line: $THEME->rendererfactory = 'theme_overridden_renderer_factory';
  2. 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.

这篇关于覆盖插件渲染器moodle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆