Extending a Theme's Custom Menu in 2.8

Extending a Theme's Custom Menu in 2.8

by Dan Olson -
Number of replies: 14

We successfully implemented a change to the custom menu that showed only enrolled courses in the custom menu. Detailed instructions were given here and they worked great. 

However, now that we've upgraded to 2.8 this fix no longer works. To be more precise -- it does display the list of enrolled courses, but it seems to completely override the way the custom menu is built and displayed, "breaking" its appearance. I am assuming this is because the custom menu in 2.8 is built in a different way?  

Has anyone successfully implemented a list of enrolled courses in the custom menu? Any advice? 


Thanks!

Average of ratings: -
In reply to Dan Olson

Re: Extending a Theme's Custom Menu in 2.8

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

You can find examples in Essential and BCU of this (maybe others as well). The principles are the same (overriding the renderer) But I suspect the details maybe slightly different with the bootstrap themes now. 

In reply to Dan Olson

Re: Extending a Theme's Custom Menu in 2.8

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

Which theme were you using previously?

There is, or should be, no reason not to use that theme in 2.8. Of course if you are and the menu is broken, then it is more than probable there is a change in the way the core renderer works now compared with how it used to work in previous versions of Moodle.

A quick way to find out is turn Debugging on.

Cheers

Mary

In reply to Dan Olson

Re: Extending a Theme's Custom Menu in 2.8

by Dan Olson -

Thanks Richard. I took a look at the Essential theme today but couldn't quite figure it out -- they have quite the group of renderers working on that theme. A bit out of my league. Will try the BECU theme tomorrow to see if I can make more sense of it. 

Mary, we were using the Arialist theme in Moodle 2.6. But we customized it probably more than we should have. So for our 2.8 upgrade we decided to clone the Clean theme to create our own theme. Everything is working great -- if I could just figure out the custom menu bit. Will keep you posted. 

Dan


In reply to Dan Olson

Re: Extending a Theme's Custom Menu in 2.8

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

Ok...the renderer you need to be looking at and comparing it with your old renderer for the Arialist them is this section of Essential/renderers/core_renderer.php highlighted in yellow...

https://github.com/gjb2048/moodle-theme_essential/blob/master/renderers/core_renderer.php#L232-L293

Just ask for help if stuck...

Cheers

Mary

In reply to Mary Evans

Re: Extending a Theme's Custom Menu in 2.8

by Philip Roy -

We had Catalyst do some work for us here in New Zealand to get the custom menu working with the Clean theme in Moodle 2.8...focussed on the "My Courses" menu that we wanted appearing on the cloned Clean theme.

I'll see if they might be willing to indicate what it was they had to fix up. We'd pointed them to the tutorial, but they had to make some changes as the info on the page you link to didn't quite work.

Phil

In reply to Philip Roy

Re: Extending a Theme's Custom Menu in 2.8

by Matt Clarkson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

To get "My Courses" working correctly in 2.8 I created the attached renderer for the clean theme.

If anyone wants to add it to their own theme based on the clean theme it should just be a matter of renaming theme_clean_core_renderer to theme_<your theme name>_core_renderer

-Matt

Average of ratings: Useful (1)
In reply to Matt Clarkson

Re: Extending a Theme's Custom Menu in 2.8

by Dan Olson -

Matt,


That works like a charm. And so much simpler, too. Thanks for that. 

I can see where the other approach published might be better for some because it's set up to include additional "this course" information in the custom menu, such as Grades.  But for our purposes this simple approach will do. 

Best,

Dan

In reply to Dan Olson

Re: Extending a Theme's Custom Menu in 2.8

by Philip Roy -

Thanks Matt,

And to endorse what Matt did for us, the menu works wonderfully on our shiny new Moodle 2.8 course hosted by Catalyst wink

Phil

In reply to Mary Evans

Re: Extending a Theme's Custom Menu in 2.8

by Dan Olson -

Thanks Philip... curious to see your approach. 

Okay, Mary... I got it working, see attached (not sure how to paste code into the forums). Can't take any credit -- I just culled the code form the BCU theme, narrowing it down to the bits that I need (which is just to display my courses in the custom menu). Seems a little overkill -- like we're re-creating the custom menu -- but it works so I'm okay with that! Comments are certainly welcome if you have any ideas to streamline or simplify what I have here. 

One thing I'm unclear on is why they had to include the breadcrumb in it as well -- but seems to break the breadcrumb nav if I don't include that bit. 

Dan



In reply to Dan Olson

Re: Extending a Theme's Custom Menu in 2.8

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

Hi Dan,

I havn't had time to read through the renderer.php fully yet. however you can delet that part about the navbar/breadcrumb as that is nothing to doe with the custommenu renderer functions.

So delete this...

    /*
     * This renders the navbar.
     * Uses bootstrap compatible html.
     */
    public function navbar() {
        $items = $this->page->navbar->get_items();
        $breadcrumbs = array();
        foreach ($items as $item) {
            $item->hideicon = true;
            $breadcrumbs[] = $this->render($item);
        }
        $divider = '<span class="divider">?</span>';
        $listitems = '<li>'.join(" $divider</li><li>", $breadcrumbs).'</li>';
        $title = '<span class="accesshide">'.get_string('pagepath').'</span>';
        return $title . "<ul class=\"breadcrumb\">$listitems</ul>";
    }
   
In reply to Mary Evans

Re: Extending a Theme's Custom Menu in 2.8

by Dan Olson -

That's what I thought too but when I delete that bit it breaks the breadcrumb. Well, to be more precise -- it doesn't actually break the breadcrumb. It just drops all the classes from the <nav> and <ul> and so on so it renders like a typical <ul> instead of picking up the CSS styling. 


In reply to Dan Olson

Re: Extending a Theme's Custom Menu in 2.8

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

Hi Dan,

I have just this minute added your renderer.php to moodle/theme/clean/renderers.php and it works fine both the menu and the breadcrumb after making the following changes...

  1. I changed the word 'theme_mytheme' to 'theme_clean' in the two instances in that file.
  2. I then made the following change to the renderer class in renderers.php so that it extends theme_bootstrapbase_core_renderer like so...
    class theme_clean_core_renderer extends theme_bootstrapbase_core_renderer {
  3. I removed the navbar function and just left the other functions that changed the custommenu.

See attached file/

Cheers

Mary

My Courses

Average of ratings: Useful (1)
In reply to Mary Evans

Re: Extending a Theme's Custom Menu in 2.8

by Dan Olson -

Brilliant Mary... thanks! I changed it to "mytheme" just to avoid confusion, so I knew about that one. But I hadn't thought to override the bootstrapbase renderer instead of core. Worked like a charm! 

Thanks again,

Dan


In reply to Dan Olson

Re: Extending a Theme's Custom Menu in 2.8

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

Hi Dan,

I'm not sure but I think it might be better in a renderers directory and called core_renderer.php instead, kind of in the same what that Bootstrapbase has it's renderers. Then the file renderers.php just takes the call from Moodle and pulls in renderers/core_renderer.php with a require_once like this.

So this is the content of the renderers.php

<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>;.

/**
 * Renderers for My Theme
 *
 * @package    theme_mytheme
 * @copyright  2015
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

require_once('renderers/core_renderer.php');

And add the highlighted line to your new renderers/core_renderer.php

require_once($CFG->dirroot.'/blocks/course_overview/locallib.php');

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

class theme_mytheme_core_renderer extends theme_bootstrapbase_core_renderer {

Which is the correct way to do things.

Cheers

Mary