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 issue #215 #216

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
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\update_navigation_menuuser;
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 update_navigation_menuuser $hook
*/
public static function update_navigation_menuuser(update_navigation_menuuser $hook): void {
// Get items to add.
$hook->add_navitems(envbarlib::add_menuuser());
}
}
34 changes: 34 additions & 0 deletions classes/local/envbarlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,4 +684,38 @@ 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();
$navitem[] = $userfirstmenu;
foreach ($envs as $env) {
$usermenu = new stdClass();
$usermenu->itemtype = 'link';
if ($env->matchpattern == '') {
//Means prod env.
$env->matchpattern = $prodwwwroot;
$usermenu->title = 'Prod';
$usermenu->url = $prodwwwroot;
} else {
$usermenu->title = $env->showtext;
$usermenu->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\update_navigation_menuuser::class,
'callback' => '\local_envbar\hook_callbacks::update_navigation_menuuser',
'priority' => 0,
]
];
Loading