How to change position of custom Site Navigation link

How to change position of custom Site Navigation link

by Barry Oosthuizen -
Number of replies: 4

Hi there,

I've added a new link to my Site Navigation block (Moodle 2.3) by using a local plugin as follows:

function logout_extends_navigation(global_navigation $navigation) {

global $CFG;

$logout_node = $navigation->add('Logout', new moodle_url($CFG->wwwroot . '/login/logout.php'), 'Logout', 1000);

}

This adds my new link to the bottom of Site Navigation tree, but I want it just below the "Home" or "My Home" link.  Is there a way to move it?

Much appreciated.

Barry

Average of ratings: -
In reply to Barry Oosthuizen

Re: How to change position of custom Site Navigation link

by Sam Hemelryk -
Hi Barry,

You should be able to do that using the add_node method which allows you to specify a node to add the new node before.
The following snippet should be pretty close to what you need.

<?php
function logout_extends_navigation(global_navigation $navigation) {
$logoutnode = navigation_node::create('Logout', new moodle_url('/login/logout.php'), 'Logout', 1000);
$navigation->add_node($logoutnode, 'site'); // The site node is right below the home/myhome nodes.
}


Hope that helps.
Sam
Average of ratings: Useful (1)
In reply to Sam Hemelryk

Re: How to change position of custom Site Navigation link

by Barry Oosthuizen -

Hi Sam,

Thanks for pointing me in the right direction.  "The site node is right below the home/myhome nodes."  That doesn't seem to work.  I changed 'site' to 'home' and now my Logout link is just below the 'Home' link which is fine.

Just for interest sake, how to I get a list of node names?

Thanks,

Barry

In reply to Barry Oosthuizen

Re: How to change position of custom Site Navigation link

by Sam Hemelryk -
Hiya,

Pretty much the only ways are to inspect the navigation structure or look at code (where the node is created).
Unfortunately you can't just var_dump the navigation structure, its huge + recursive so normally results in an error.
If you have a look at https://moodle.org/mod/forum/discuss.php?d=218358 and my post there I've shared a file that contains a function that can be used to print out the navigation structure.
That may be of help.

Cheers
Sam
Average of ratings: Useful (1)