Skip to content

Commit

Permalink
Add call to hook update_navigation_item and add env in menu
Browse files Browse the repository at this point in the history
  • Loading branch information
gbarat87 committed Jul 19, 2024
1 parent 2081682 commit 722dc28
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions classes/hook_callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace local_envbar;

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 @@ -38,4 +39,14 @@ public static function before_standard_top_of_body_html_generation(before_standa
// Get code to inject.
$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.
$hook->add_navitems(envbarlib::add_menuuser());
}
}
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 @@ -31,4 +31,9 @@
'callback' => '\local_envbar\hook_callbacks::before_standard_top_of_body_html_generation',
'priority' => 0,
],
[
'hook' => core_user\hook\extend_user_menu::class,
'callback' => '\local_envbar\hook_callbacks::extend_user_menu',
'priority' => 0,
]
];

0 comments on commit 722dc28

Please sign in to comment.