From c63c192f45c5bb1192dbf3e7d16bebda670400db Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 20 Aug 2024 00:35:07 +0800 Subject: [PATCH 1/1] example --- mod/forum/lib.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 849b18c06d..1772189f49 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -6912,3 +6912,41 @@ function forum_refresh_events(int $courseid, stdClass $instance, stdClass $cm): forum_update_calendar($instance, $cm->id); } + +function mod_forum_extend_navigation_user( + $usernode, + $user, + $usercontext, + $course, + $coursecontext, +): void { + global $CFG, $SITE; + if (!empty($CFG->navadduserpostslinks) && $coursecontext instanceof \core\context\system) { + $baseargs = ['id' => $user->id]; + + // Add nodes for forum posts and discussions if the user can view either or both + // There are no capability checks here as the content of the page is based + // purely on the forums the current user has access too. + $forumtab = \navigation_node::create(get_string('forumposts', 'forum')); + $forumtab->add( + get_string('posts', 'forum'), + new moodle_url('/mod/forum/user.php', $baseargs), + ); + $forumtab->add( + get_string('discussions', 'forum'), + new moodle_url('/mod/forum/user.php', + array_merge($baseargs, ['mode' => 'discussions']), + ), + ); + + // We add the forum link either immediately after the 'viewuserdetails' link, or as the first item in the list. + foreach ($usernode->children as $child) { + if ($child->key === 'viewuserdetails') { + continue; + } + $addbefore = $child; + break; + } + $usernode->add_node($forumtab, $addbefore->key); + } +} -- 2.42.0