diff --git a/.upgradenotes/MDL-71823-2024091304403638.yml b/.upgradenotes/MDL-71823-2024091304403638.yml new file mode 100644 index 0000000000000..7390792be597f --- /dev/null +++ b/.upgradenotes/MDL-71823-2024091304403638.yml @@ -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 diff --git a/user/classes/hook/extend_user_menu.php b/user/classes/hook/extend_user_menu.php index f6bfb72023cc5..418d94eef148d 100644 --- a/user/classes/hook/extend_user_menu.php +++ b/user/classes/hook/extend_user_menu.php @@ -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; + } } } diff --git a/user/lib.php b/user/lib.php index 031f1980a7a12..c9339908c0906 100644 --- a/user/lib.php +++ b/user/lib.php @@ -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) {