Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add call to hook update_navigation_item fix #215 #217

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions classes/hook_callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require_once($CFG->dirroot . '/local/envbar/lib.php');

use core\hook\output\before_standard_top_of_body_html_generation;
use core_user\hook\extend_user_menu;
use local_envbar\local\envbarlib;

/**
Expand All @@ -43,6 +44,19 @@ public static function before_standard_top_of_body_html_generation(before_standa
$hook->add_html(envbarlib::get_inject_code());
}

/**
* This is the hook enables the plugin to add one or more menu item.
*
* @param extend_user_menu $hook
*/
public static function extend_user_menu(extend_user_menu $hook): void {
// Get items to add.
$navitems = envbarlib::add_menuuser();
foreach ($navitems as $item) {
$hook->add_navitem($item);
}
}

/**
* Listener for the after_config hook.
*
Expand Down
30 changes: 30 additions & 0 deletions classes/local/envbarlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,4 +684,34 @@ public static function config() {
}
}

/**
* Add items to the menu navigation.
*
* @return array New menu items.
*/
public static function add_menuuser(): array {
$userfirstmenu = new stdClass();
$userfirstmenu->itemtype = 'divider';
$envs = self::get_records();
$here = (new moodle_url('/'))->out();
$prodwwwroot = self::getprodwwwroot();
$prodenv = new stdClass();
$prodenv->matchpattern = $prodwwwroot;
$prodenv->showtext = get_string('prod', 'local_envbar');
$envs[] = $prodenv;
$navitem[] = $userfirstmenu;
foreach ($envs as $env) {
$usermenu = new stdClass();
$usermenu->itemtype = 'link';
$usermenu->title = $env->showtext;
$usermenu->url = new moodle_url($env->matchpattern);
// Which env matches?
if (self::is_match($here, $env->matchpattern)) {
$usermenu->pix = 'e/tick';
}
$navitem[] = $usermenu;
}
return $navitem;
}

}
5 changes: 5 additions & 0 deletions db/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@
'hook' => \core\hook\after_config::class,
'callback' => [\local_envbar\hook_callbacks::class, 'after_config'],
],
[
'hook' => core_user\hook\extend_user_menu::class,
'callback' => '\local_envbar\hook_callbacks::extend_user_menu',
'priority' => 0,
],
];
Loading