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
Core developersDocumentation writersParticularly helpful MoodlersPlugin developersTesters

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
Core developersDocumentation writersParticularly helpful MoodlersPlugin 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
Core developersDocumentation writersParticularly helpful MoodlersPlugin 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
Core developersMoodle HQParticularly helpful MoodlersPlugin developersTesters

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
Core developersDocumentation writersParticularly helpful MoodlersPlugin 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
Core developersMoodle HQParticularly helpful MoodlersPlugin developersTesters
              // 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
Particularly helpful MoodlersPlugin 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: -
Picture of Bas Harkink
Re: Moodle 3.2 - Navigation Drawer
 

For removing items there is. Just use CSS. Add the next line to the theme (custom) CSS:

[data-key="participants"] {display: none;}

To hide multiple items, just copy the line, add it to the CSS and replace "participants" with the name of the item.

For adding items you can not use SCC. Theme Fordson has the capacity to add/remove items, you might integrate that into your theme or contact the maintainer for the theme. 


On general principle I would advise to stay away from changing code in Moodle core to prevent loss of functionality during upgrades.

 
Average of ratings: -
It's only an avatar...
Re: Moodle 3.2 - Navigation Drawer
Core developersDocumentation writersParticularly helpful MoodlersPlugin developersTesters

Hi Bas,

I would strongly disagree with your suggestion above, which appears to just randomly hide instances of the data-key in a themes custom CSS settings, without first adding a prefix class selector relating to the part of the page you are targeting.

Goodness me who knows what mayhem may result from such.

Mary

 
Average of ratings: -
Picture of Bas Harkink
Re: Moodle 3.2 - Navigation Drawer
 

Hello Mary,

In the instance we were using this CSS we wanted to hide the Nav drawer items in the entire site. To make sure to only target the Nav drawer add the id “#nav-drawer” to the CSS. That will result in the line below:

#nav-drawer [data-key="participants"] {display: none;}

The result will be the same and no mayhem is caused anywhere besides the nav drawer. Or am I missing something?

 
Average of ratings: -
It's only an avatar...
Re: Moodle 3.2 - Navigation Drawer
Core developersDocumentation writersParticularly helpful MoodlersPlugin developersTesters

hi Bas,

I stand corrected. No you were not missing anything, but apparently I was! 

I had not realised that "data-key" only related to the Nav Drawer...it's amaising how much I have learned by making wrong assumptions. At least it gets some useful bits of information out into the open, and not left in the dark annals of Moodle code.

Thanks

Mary

 
Average of ratings: -