Heads up about changes to build_navigation

Heads up about changes to build_navigation

by Tim Hunt -
Number of replies: 7
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
In 1.9, there is a new function called build_navigation, which makes it easier to build the navigation bar, and also, because navigation all goes through one function, it makes it easier to customise. (I can't remember who takes credit for this, but it is a great idea.)

I was using this and had some ideas about making it much easier to use in some common cases. That is issue MDL-11699, and there is now what I hope is a very clear doc comment above that function in weblib.php. Also, I wrote http://docs.moodle.org/en/Development:lib/weblib.php.

The second thing I did was MDL-11741. This is converting all the core modules to take advantage of the changes to build_navigation. Doing this removes about 400 lines of fairly repetitive code from all the modules, but it is a big (though low risk) change. Therefore, so far, I have just committed it to HEAD. I think it would be good to commit this to 1.9 beta too, but it may be too much of a risk. What do people think?

In the near future, if you find any navigation-bar related problems in modules, please feel free to file them in the tracker, and assign them to me (user timhunt).

It would be great if people are able to test all modules in HEAD, but I guess most testing is focussing on 1.9 at the moment.
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Heads up about changes to build_navigation

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
OK, I just browbeat Martin into letting me check this into 1.9. Testers, please note.
In reply to Tim Hunt

Re: Heads up about changes to build_navigation

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Tim - Nothing ventured, nothing gained. I will see if I can give a quick run through but simplifying the code sounds like a wonderful thing to me. Thanks for browbeating (unless it breaks everything in which case we will know who to blame). Speaking of cases, I still owe you a beer but I'll let you recover from the current Moot first. Peace - Anthony
In reply to Anthony Borrow

Re: Heads up about changes to build_navigation

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Well, I hope I did not browbeat him too much. But I was desparately trying to get everything finished before leaving work on a Friday afternoon, but also get to an orchestra rehearsal on time. In the end I was a bit late, but got away with it.

However, if anyone is in the vicinity of Milton Keynes next Friday lunchtime, this concert, is going to be well worth hearing, even if I do say so myself.
In reply to Tim Hunt

Re: Heads up about changes to build_navigation

by Chardelle Busch -
Picture of Core developers
Hey Tim,

I was wondering if you could give me a little help with the build navigation for the activity locking hack. The lock file nav is a little different since it gets the name of the mod that is being linked -- sorry to be a pest-- thanks.

$instance = get_record($mods[$id]->modname, "id", $mods[$id]->instance);
print_header($course->shortname.': '.$stractivitylocks, $course->fullname,
'<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->shortname.'</a> -> '.$instance->name.': '.$stractivitylocks);



In reply to Chardelle Busch

Re: Heads up about changes to build_navigation

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Does this intentionally leave out the 'Quizzes'/'Forums' level links?

If you want to be more consistent with navigation on other pages, probably what you want is

$navigation = build_navigation($stractivitylocks, $mods[$id]);
print_header($course->shortname.': '.$stractivitylocks, $course->fullname, $navigation);

But to replicate exactly what you have now, it would need to be

$instancename = get_field($mods[$id]->modname, 'name', "id", $mods[$id]->instance);
$navigation = build_navigation($instance->name.': '.$stractivitylocks);
print_header($course->shortname.': '.$stractivitylocks, $course->fullname, $navigation);
In reply to Tim Hunt

Re: Heads up about changes to build_navigation

by Chardelle Busch -
Picture of Core developers
Got it, thanks Tim.

No need to drill down to mod levels, this is just a generic page that is called for any given activity.
In reply to Tim Hunt

Re: Heads up about changes to build_navigation

by Gary Anderson -
A limitation of using the build_navigation function is that it makes the code incompatible with versions prior to 1.9 (and will in fact lead to a fatal error because the function will not be found).

A work around is to call

if (function_exists('build_navigation'))

and use legacy code to produce the navigation element if the build_variable function is not available.

If your target version is only 1.9 or greater, this is, of course, not needed.