Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Interface and classes for creating appropriate renderers for various parts of Moodle. Please see http://docs.moodle.org/en/Developement:How_Moodle_outputs_HTML for an overview.

Copyright: 2009 Tim Hunt
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 449 lines (19 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 4 classes

renderer_factory:: (1 method):
  get_renderer()

renderer_factory_base:: (3 methods):
  __construct()
  get_target_suffix()
  standard_renderer_classnames()

standard_renderer_factory:: (1 method):
  get_renderer()

theme_overridden_renderer_factory:: (2 methods):
  __construct()
  get_renderer()


Interface: renderer_factory  - X-Ref

A renderer factory is just responsible for creating an appropriate renderer
for any given part of Moodle.

Which renderer factory to use is chose by the current theme, and an instance
if created automatically when the theme is set up.

A renderer factory must also have a constructor that takes a theme_config object.
(See {@link renderer_factory_base::__construct} for an example.)

get_renderer(moodle_page $page, $component, $subtype=null, $target=null)   X-Ref
Return the renderer for a particular part of Moodle.

The renderer interfaces are defined by classes called {plugin}_renderer
where {plugin} is the name of the component. The renderers for core Moodle are
defined in lib/renderer.php. For plugins, they will be defined in a file
called renderer.php inside the plugin.

Renderers will normally want to subclass the renderer_base class.
(However, if you really know what you are doing, you don't have to do that.)

There is no separate interface definition for renderers. The default
{plugin}_renderer implementation also serves to define the API for
other implementations of the interface, whether or not they subclass it.

A particular plugin can define multiple renderers if it wishes, using the
$subtype parameter. For example workshop_renderer,
workshop_allocation_manual_renderer etc.

param: moodle_page $page the page the renderer is outputting content for.
param: string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
param: string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
param: string $target one of rendering target constants
return: renderer_base an object implementing the requested renderer interface.

Class: renderer_factory_base  - X-Ref

This is a base class to help you implement the renderer_factory interface.

It keeps a cache of renderers that have been constructed, so you only need
to construct each one once in you subclass.

It also has a method to get the name of, and include the renderer.php with
the definition of, the standard renderer class for a given module.

__construct(theme_config $theme)   X-Ref
Constructor.

param: theme_config $theme the theme we belong to.

get_target_suffix($target)   X-Ref
Returns suffix of renderer class expected for given target.

param: string $target one of the renderer target constants, target is guessed if null used
return: array two element array, first element is target, second the target suffix string

standard_renderer_classnames($component, $subtype = null)   X-Ref
For a given module name, return the possible class names
that defines the renderer interface for that module.

Newer auto-loaded class names are returned as well as the old style _renderable classnames.

Also, if it exists, include the renderer.php file for that module, so
the class definition of the default renderer has been loaded.

param: string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
param: string $subtype optional subtype such as 'news' resulting to:
return: array[] Each element of the array is an array with keys:

Class: standard_renderer_factory  - X-Ref

This is the default renderer factory for Moodle.

It simply returns an instance of the appropriate standard renderer class.

get_renderer(moodle_page $page, $component, $subtype = null, $target = null)   X-Ref
Implement the subclass method

param: moodle_page $page the page the renderer is outputting content for.
param: string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
param: string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
param: string $target one of rendering target constants
return: renderer_base an object implementing the requested renderer interface.

Class: theme_overridden_renderer_factory  - X-Ref

This is renderer factory allows themes to override the standard renderers using php code.

It will load any code from theme/mytheme/renderers.php and
theme/parenttheme/renderers.php, if then exist. Then whenever you ask for
a renderer for 'component', it will create a mytheme_component_renderer or a
parenttheme_component_renderer, instead of a component_renderer,
if either of those classes exist.

__construct(theme_config $theme)   X-Ref
Constructor.

param: theme_config $theme the theme we are rendering for.

get_renderer(moodle_page $page, $component, $subtype = null, $target = null)   X-Ref
Implement the subclass method

param: moodle_page $page the page the renderer is outputting content for.
param: string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
param: string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
param: string $target one of rendering target constants
return: renderer_base an object implementing the requested renderer interface.