Overriding an abstract class in a theme

Overriding an abstract class in a theme

by David ARNOULT -
Number of replies: 4

Hi!

I try to override in my theme the function section_header in the abstract class format_section_renderer_base located in 

course/format/renderer.php

I do not know what class name I need to declare in my new class. Can I extend an abstract class btw?

abstract class theme_test_core_course_format_renderer extends format_section_renderer_base
or

abstract class theme_test_format_section_renderer_base extends format_section_renderer_base
or ?
What is the name of the file of the renderer, abstract class of path of the class (
format_section_renderer_base or core_course_format_renderer) ?

Some incomplete information have been already given here
https://moodle.org/mod/forum/discuss.php?d=396419

I have followed the process https://docs.moodle.org/dev/Overriding_a_renderer#Overriding_a_component.27s_renderer
Moodle 3.9 with lambda theme.

Thanks for your support

Average of ratings: -
In reply to David ARNOULT

Re: Overriding an abstract class in a theme

by David ARNOULT -
In fact I am confused as the renderer class does not follow the physical path of the files course_format_renderer / format_section_renderer_base... I have tried with both without success. There's no example in this case in the official documentation.
In reply to David ARNOULT

Re: Overriding an abstract class in a theme

by David ARNOULT -
renderers.php

require_once('renderers/core_renderer.php');
require_once('renderers/core_course_renderer.php');
require_once('renderers/mod_assign_renderer.php');
require_once('renderers/format_section_renderer_base.php');


format_section_renderer_base.php in folder "renderers"

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . "/course/format/renderer.php");
abstract class theme_lambda_format_section_renderer_base extends format_section_renderer_base {
...
}

$THEME->rendererfactory = 'theme_overridden_renderer_factory'; is set obviously in config.php...

In reply to David ARNOULT

Re: Overriding an abstract class in a theme

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
abstract? Your class should override the course format version not the base class. To learn about OO in PHP see: https://www.php.net/manual/en/language.oop5.php - to learn about how Moodle autoloads and extends classes, see: https://docs.moodle.org/dev/Automatic_class_loading.
In reply to Gareth J Barnard

Re: Overriding an abstract class in a theme

by David ARNOULT -
Thanks Gareth for the tips. I will explorer these resources and will try to manage.