From 017829142d47934a1f04337dadb15ff36498d148 Mon Sep 17 00:00:00 2001 From: guillaumebarat <guillaumebarat@catalyst-au.net> Date: Fri, 13 Sep 2024 14:07:58 +1000 Subject: [PATCH] MDL-71823 user: Add hook for extending user menu post review --- .upgradenotes/MDL-71823-2024091304403638.yml | 7 +++++++ user/classes/hook/extend_user_menu.php | 9 ++++++--- user/lib.php | 4 +--- 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 .upgradenotes/MDL-71823-2024091304403638.yml diff --git a/.upgradenotes/MDL-71823-2024091304403638.yml b/.upgradenotes/MDL-71823-2024091304403638.yml new file mode 100644 index 000000000000..7390792be597 --- /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 f6bfb72023cc..418d94eef148 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 031f1980a7a1..c9339908c090 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) {