mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
Merge branch 'MDL-61869_master' of https://github.com/marxjohnson/moodle
This commit is contained in:
commit
6502ba9a26
@ -194,14 +194,16 @@ class renderer_base {
|
||||
* If will then be rendered by a method based upon the classname for the widget.
|
||||
* For instance a widget of class `crazywidget` will be rendered by a protected
|
||||
* render_crazywidget method of this renderer.
|
||||
* If no render_crazywidget method exists and crazywidget implements templatable,
|
||||
* look for the 'crazywidget' template in the same component and render that.
|
||||
*
|
||||
* @param renderable $widget instance with renderable interface
|
||||
* @return string
|
||||
*/
|
||||
public function render(renderable $widget) {
|
||||
$classname = get_class($widget);
|
||||
$classparts = explode('\\', get_class($widget));
|
||||
// Strip namespaces.
|
||||
$classname = preg_replace('/^.*\\\/', '', $classname);
|
||||
$classname = array_pop($classparts);
|
||||
// Remove _renderable suffixes
|
||||
$classname = preg_replace('/_renderable$/', '', $classname);
|
||||
|
||||
@ -209,6 +211,15 @@ class renderer_base {
|
||||
if (method_exists($this, $rendermethod)) {
|
||||
return $this->$rendermethod($widget);
|
||||
}
|
||||
if ($widget instanceof templatable) {
|
||||
$component = array_shift($classparts);
|
||||
if (!$component) {
|
||||
$component = 'core';
|
||||
}
|
||||
$template = $component . '/' . $classname;
|
||||
$context = $widget->export_for_template($this);
|
||||
return $this->render_from_template($template, $context);
|
||||
}
|
||||
throw new coding_exception('Can not render widget, renderer method ('.$rendermethod.') not found.');
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user