Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
renderer_factory_base Class Reference

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

Inheritance diagram for renderer_factory_base:
renderer_factory standard_renderer_factory theme_overridden_renderer_factory

Public Member Functions

 __construct (theme_config $theme)
 Constructor.
 
 get_renderer (moodle_page $page, $component, $subtype=null, $target=null)
 Return the renderer for a particular part of Moodle.
 

Protected Member Functions

 get_target_suffix ($target)
 Returns suffix of renderer class expected for given target.
 
 standard_renderer_classnames ($component, $subtype=null)
 For a given module name, return the possible class names that defines the renderer interface for that module.
 

Protected Attributes

theme_config $theme
 The theme we belong to.
 

Detailed Description

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.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Since
Moodle 2.0

Constructor & Destructor Documentation

◆ __construct()

renderer_factory_base::__construct ( theme_config $theme)

Constructor.

Parameters
theme_config$themethe theme we belong to.

Reimplemented in theme_overridden_renderer_factory.

Member Function Documentation

◆ get_renderer()

renderer_factory::get_renderer ( moodle_page $page,
$component,
$subtype = null,
$target = null )
inherited

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.

Parameters
moodle_page$pagethe page the renderer is outputting content for.
string$componentname such as 'core', 'mod_forum' or 'qtype_multichoice'.
string$subtypeoptional subtype such as 'news' resulting to 'mod_forum_news'
string$targetone of rendering target constants
Return values
renderer_basean object implementing the requested renderer interface.

Implemented in standard_renderer_factory, and theme_overridden_renderer_factory.

◆ get_target_suffix()

renderer_factory_base::get_target_suffix ( $target)
protected

Returns suffix of renderer class expected for given target.

Parameters
string$targetone of the renderer target constants, target is guessed if null used
Return values
arraytwo element array, first element is target, second the target suffix string

◆ standard_renderer_classnames()

renderer_factory_base::standard_renderer_classnames ( $component,
$subtype = null )
protected

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.

Parameters
string$componentname such as 'core', 'mod_forum' or 'qtype_multichoice'.
string$subtypeoptional subtype such as 'news' resulting to: 'mod_forum\output\news_renderer' or 'mod_forum\output\news\renderer' or non-autoloaded 'mod_forum_news'
Return values
array[]Each element of the array is an array with keys: classname - The class name to search autoloaded - Does this classname assume autoloading? validwithprefix - Is this class name valid when a prefix is added to it? validwithoutprefix - Is this class name valid when no prefix is added to it?
Exceptions
coding_exception

The documentation for this class was generated from the following file: