Skip to content

Commit

Permalink
MDL-33592 navigation: Added support for local_ prefix on navigation c…
Browse files Browse the repository at this point in the history
…allback
  • Loading branch information
Sam Hemelryk committed Jun 12, 2012
1 parent f8dfdb5 commit 5c1f0d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
13 changes: 7 additions & 6 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1423,14 +1423,15 @@ public function initialise() {
}

// Give the local plugins a chance to include some navigation if they want.
foreach (get_list_of_plugins('local') as $plugin) {
if (!file_exists($CFG->dirroot.'/local/'.$plugin.'/lib.php')) {
continue;
}
require_once($CFG->dirroot.'/local/'.$plugin.'/lib.php');
$function = $plugin.'_extends_navigation';
foreach (get_plugin_list_with_file('local', 'lib.php', true) as $plugin => $file) {
$function = "local_{$plugin}_extends_navigation";
$oldfunction = "{$plugin}_extends_navigation";
if (function_exists($function)) {
// This is the preferred function name as there is less chance of conflicts
$function($this);
} else if (function_exists($oldfunction)) {
// We continue to support the old function name to ensure backwards compatability
$oldfunction($this);
}
}

Expand Down
5 changes: 3 additions & 2 deletions local/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,11 @@ These two functions both need to be defined within /local/nicehack/lib.php.

sample code
<?php
function nicehack_extends_navigation(global_navigation $nav) {
function local_nicehack_extends_navigation(global_navigation $nav) {
// $nav is the global navigation instance.
// Here you can add to and manipulate the navigation structure as you like.
// This callback was introduced in 2.0
// This callback was introduced in 2.0 as nicehack_extends_navigation(global_navigation $nav)
// In 2.3 support was added for the now preferred local_nicehack_extends_navigation(global_navigation $nav).
}
function local_nicehack_extends_settings_navigation(settings_navigation $nav, context $context) {
// $nav is the settings navigation instance.
Expand Down

0 comments on commit 5c1f0d1

Please sign in to comment.