Skip to content

Commit

Permalink
MDL-71823 user: Add hook for extending user menu post review
Browse files Browse the repository at this point in the history
  • Loading branch information
gbarat87 committed Sep 13, 2024
1 parent 0bfa1bc commit 0178291
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .upgradenotes/MDL-71823-2024091304403638.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
issueNumber: MDL-71823
notes:
core_user:
- message: >-
New '\core_user\hook\extend_user_menu' hook added to allow third party
plugin to extend the user menu navigation
type: improved
9 changes: 6 additions & 3 deletions user/classes/hook/extend_user_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ public function __construct(
}

/**
* Add navigation item.
*
* @param null|array $output
* @param null|\stdClass $output
*/
public function add_navitems(?array $output): void {
public function add_navitem(?\stdClass $output): void {
if ($output) {
$this->navitems = $output;
if (property_exists($output, 'itemtype')) {
$this->navitems[] = $output;
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions user/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,7 @@ function user_get_user_navigation_info($user, $page, $options = array()) {
di::get(core\hook\manager::class)->dispatch($hook);
$hookitems = $hook->get_navitems();
foreach ($hookitems as $menuitem) {
if (property_exists($menuitem, 'itemtype')) {
$returnobject->navitems[] = $menuitem;
}
$returnobject->navitems[] = $menuitem;
}

if ($custommenucount > 0) {
Expand Down

0 comments on commit 0178291

Please sign in to comment.