diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 24a175bb3214b..80d9953d3e544 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -2589,16 +2589,6 @@ protected function load_for_user($user=null, $forceforcontext=false) { } } - if (!empty($CFG->navadduserpostslinks)) { - // 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 = $usernode->add(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, array('mode' => 'discussions')))); - } - // Add blog nodes. if (!empty($CFG->enableblogs)) { if (!$this->cache->cached('userblogoptions'.$user->id)) { @@ -5201,16 +5191,6 @@ protected function generate_user_settings($courseid, $userid, $gstitle='usercurr $profilenode = $mainpage->add(get_string('profile'), new moodle_url('/user/profile.php', array('id' => $user->id)), self::TYPE_SETTING, null, 'myprofile'); - if (!empty($CFG->navadduserpostslinks)) { - // 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 = $profilenode->add(get_string('forumposts', 'forum')); - $forumtab->add(get_string('posts', 'forum'), new moodle_url('/mod/forum/user.php', $baseargs), null, 'myposts'); - $forumtab->add(get_string('discussions', 'forum'), new moodle_url('/mod/forum/user.php', - array_merge($baseargs, array('mode' => 'discussions'))), null, 'mydiscussions'); - } - // Add blog nodes. if (!empty($CFG->enableblogs)) { if (!$this->cache->cached('userblogoptions'.$user->id)) { diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 849b18c06d986..ecfaea1d91a53 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -6912,3 +6912,50 @@ function forum_refresh_events(int $courseid, stdClass $instance, stdClass $cm): forum_update_calendar($instance, $cm->id); } + +/** + * Callback adds navigation to view user posts if the navadduserpostslinks config is on. + * + * @param navigation_node $usernode User node within navigation + * @param stdClass $user User object + * @param \core\context\user $usercontext User context + * @param stdClass $course Current course + * @param \core\context $coursecontext Course context + */ +function mod_forum_extend_navigation_user( + navigation_node $usernode, + stdClass $user, + \core\context\user $usercontext, + stdClass $course, + \core\context $coursecontext, +): void { + global $CFG; + 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); + } +} diff --git a/mod/forum/version.php b/mod/forum/version.php index 2a5cac776fa33..06b343adf5fb3 100644 --- a/mod/forum/version.php +++ b/mod/forum/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024042200; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2024082100; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2024041600; // Requires this Moodle version. $plugin->component = 'mod_forum'; // Full name of the plugin (used for diagnostics)