Themes

Moodle 3.2 - Navigation Drawer

 
Picture of Callum Booth
Moodle 3.2 - Navigation Drawer
 

Hello, 


I wondered if was possible to add or remove items that appear in the new Navigation Drawer that was introduced into 3.2.


I understand that an array is generated in lib/navigationlib.php and then that array is used in the flat_navigation.mustache template to generate the html to display the drawer. Could a renderer or another method be used to add/remove items from the array.


Many Thanks

Callum

 
Average of ratings: -
It's only an avatar...
Re: Moodle 3.2 - Navigation Drawer
Group Core developersGroup Documentation writersGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

Hi Callum,

To tell you the truth, I'm not sure as the Boost theme is still very much a mystery to me too, but I dare say the answer will be no. Have you searched through the Moodle docs?

If you could add or remove items, what would you remove, and what would you add?

If this does not exist the the only way to get something like this into Moodle would be to ask for those extra settings, by creating a New Improvement issue using the Moodle Tracker.

Cheers

Mary

 
Average of ratings: -
Picture of Callum Booth
Re: Moodle 3.2 - Navigation Drawer
 

HI Mary,


I have had a look through the docs and there isn't anything which highlights how to add/remove items from the navigation drawer.


At this stage there isn't a specific need to add or remove any specific items however its likely in the future that a client asks for an item to be added or removed.


Many Thanks

Callum

 
Average of ratings: -
Picture of Howard Miller
Re: Moodle 3.2 - Navigation Drawer
Group Core developersGroup Documentation writersGroup Particularly helpful MoodlersGroup Plugin developers

I'd like to know the same thing (well, just to add). I've spent quite a while digging through the Boost code but a lot of it (sorry) is really difficult to follow. Which is a shame. 

It's easy enough to find the mustache template that renders the thing but that must be called with an array of actions. I *think* (ie. could be talking rubbish), that this is a collection as follows...

$PAGE->flatnav

This is an instance of a class 'flat_navigation' defined in lib/navigationlib.php

If you can get hold of it, you can possibly manipulate it. 

More work to do...

 
Average of ratings: -
Picture of Howard Miller
Re: Moodle 3.2 - Navigation Drawer
Group Core developersGroup Documentation writersGroup Particularly helpful MoodlersGroup Plugin developers

Ok, I have a way to extend the menu in a custom theme. This suits me... you can probably manipulate the collection to delete any required links too. 

I had already created a child theme of boost and I then copied over the columns2.php layout from boost to my child theme. 

The critical line in the layout (there isn't much in it any more as the templates do everything) is...

$templatecontext['flatnavigation'] = $PAGE->flatnav;

This loads the 'flat navigation' collection into the context that will be sent off to mustache. We can fiddle about with it before this. 

I added the following immediately before the above line (I wanted to add a link to the dashboard in the moodle 'extension' Iomad)...

// Add Iomad link
$url = new moodle_url('/local/iomad_dashboard/index.php');
$iomaddashboard = navigation_node::create(get_string('iomaddashboard', 'theme_iomadboost'), $url);
$flat = new flat_navigation_node($iomaddashboard, 0);
$flat->set_showdivider(true);
$flat->key = 'iomad';
$PAGE->flatnav->add($flat);
$templatecontext['flatnavigation'] = $PAGE->flatnav;


This code was simply stolen from the initialisation code in navigation lib. Works as you would expect.

 
Average of ratings: Useful (1)
Me!
Re: Moodle 3.2 - Navigation Drawer
Group Core developersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

You can set the property $showinflatnav on any node in the navigation tree and it will be displayed in the drawer - or you can manually build a node as shown here - but I really do not recommend it. The flat navigation is not supposed to contain every link to every place you could go in Moodle - only the very most important things. We will keep refining it in future as we do user testing on the navigation (and the more you customise it the more conflicts you will have with our future changes). 



 
Average of ratings: Useful (2)
Picture of Howard Miller
Re: Moodle 3.2 - Navigation Drawer
Group Core developersGroup Documentation writersGroup Particularly helpful MoodlersGroup Plugin developers

Mine is a bit of an unusual case (linking to a big chunk of functionality that doesn't exist in standard Moodle), so I'm happy to do this but I understand your point completely. 

It's an interesting intellectual exercise anyway... theme code is becoming unrecognisable from how it was a few versions ago. 

Anyway, how does one add the $showinflatnav property when creating a node. I'm specifically talking about when adding new navigation nodes as described in local/readme.txt (adding, say, a new admin_category instance)? Perhaps this is getting a bit too specific...

 
Average of ratings: -
Me!
Re: Moodle 3.2 - Navigation Drawer
Group Core developersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers
              // Calendar                                                                                                             
              $calendarurl = new moodle_url('/calendar/view.php', array('view' => 'month'));                                          
              $node = $coursenode->add(get_string('calendar', 'calendar'), $calendarurl, self::TYPE_CUSTOM, null, 'calendar');        
              $node->showinflatnavigation = true;                    
Example ^.
 
Average of ratings: Useful (1)
Picture of Chris Kenniburg
Re: Moodle 3.2 - Navigation Drawer
Group Particularly helpful MoodlersGroup Plugin developers

Where exactly would you put this? In the layout file?

 
Average of ratings: -
Picture of Vimal Saifudin
Re: Moodle 3.2 - Navigation Drawer
 

I think it must be added to

moodle/lib/navigationlib.php

 
Average of ratings: -
Picture of Martin Williams
Re: Moodle 3.2 - Navigation Drawer
 

Could you post an example of how to remove a link? I have a client that wants to remove the Dashboard link, and I haven't been able to figure it out.

 
Average of ratings: -
Picture of Vimal Saifudin
Re: Moodle 3.2 - Navigation Drawer
 

If you want to hide dashboard from flatnavigation try this:

$this->rootnodes['home']->showinflatnavigation = false;


Search for get_string('myhome')  to find its occurrences in any other places


 
Average of ratings: -
Picture of Martin Williams
Re: Moodle 3.2 - Navigation Drawer
 

Thanks for the response.

Is there a way to accomplish this without modifying the core code? I'd like to not have to make this change every time we update Moodle.

 
Average of ratings: -