[RESOLVED] Do/should renderer overrides cascade through themes

[RESOLVED] Do/should renderer overrides cascade through themes

by Howard Miller -
Number of replies: 12
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I am creating a theme that is based on the Bootstrap3 theme (i.e. that theme is its parent).

I wanted to modify the appearance of the breadcrumb trail so I overrode the core_renderer and wrote my own code for that function. It works fine. 

Unfortunately, a lot of other things are suddenly broken. It appears that Moodle is no longer 'seeing' the renderer overrides in the Bootstrap theme (well, I am assuming that). Is this to be expected? Do I need to copy the entire core_renderer code from the bootstrap3 theme into mine?

EDIT:
Just to try it - I did copy the whole class from bootstrap and it fixed the problems. So that does appear to be the case. Unless I am missing something of course. 

(Edited by Mary Evans - MARKED AS RESOLVED - original submission Thursday, 14 May 2015, 11:28 AM)

Average of ratings: -
In reply to Howard Miller

Re: Do/should renderer overrides cascade through themes

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Howard,

You only need to override what you want to change.  If you had to copy the whole class, then the inheritance chain is broken.  So its a 'daisy chain' being theme_yourtheme_core_renderer -> theme_bootstrap_core_renderer -> core_renderer.  See: https://github.com/gjb2048/moodle-theme_shoehorn/blob/MOODLE_27/renderers/core_renderer.php#L30 which chains with: https://github.com/bmbrands/theme_bootstrap/blob/master/renderers/core_renderer.php#L27.

Cheers,

Gareth

Average of ratings: Useful (1)
In reply to Gareth J Barnard

Re: Do/should renderer overrides cascade through themes

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hmmm... that's what I was expecting. I wonder why it didn't work then...

In reply to Howard Miller

Re: Do/should renderer overrides cascade through themes

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Have you put ...

$THEME->rendererfactory = 'theme_overridden_renderer_factory';

in your theme's config.php?

In reply to Mary Evans

Re: Do/should renderer overrides cascade through themes

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yep... 

As I say... it worked, but the methods in the parent theme (bootstrap) where now not honoured and it reverted to the core_renderer methods. That is despite the parent being bootstrap my own renderer methods were honoured but the parent renderer methods appear to be ignored.

In reply to Howard Miller

Re: Do/should renderer overrides cascade through themes

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Are you still calling the original bootstrap renderer into your core_renderer.php with this line...

include_once ($CFG->dirroot . '/theme/bootstrap/renderers/core_renderer.php');

For example:

https://github.com/gjb2048/moodle-theme_shoehorn/blob/MOODLE_27/renderers/core_renderer.php#L28

In reply to Mary Evans

Re: Do/should renderer overrides cascade through themes

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

No... I have no includes at all. Should I have?

EDIT:
Ahhh.... should I be extending the parent (i.e. bootstrap) renderer class rather than core_renderer?

That's it isn't it? blush

In reply to Howard Miller

Re: Do/should renderer overrides cascade through themes

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Priceless!

In reply to Mary Evans

Re: Do/should renderer overrides cascade through themes

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I do my best, but even I can't be perfect all the time. It wouldn't be fair to others wink

In reply to Howard Miller

Re: Do/should renderer overrides cascade through themes

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Put us out of our misery,  Howard, please tell us if it is working now?

Cheers

Mary

In reply to Mary Evans

Re: Do/should renderer overrides cascade through themes

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yep - it works perfectly. Thanks.

Like all the best bugs - completely obvious once you know what the answer is!