MDL-82359 mod_forum: Move user posts links logic into module
The logic about adding links to view user posts in the forum module was previously in core code, but there is an existing callback that means this can be implemented entirely within the forum module. Co-authored-by: sam marshall <[email protected]>
This commit is contained in:
committed by
sam marshall
co-authored by
sam marshall
parent
cdd8cbb3b9
commit
553480e044
@@ -2589,16 +2589,6 @@ class global_navigation extends navigation_node {
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ class settings_navigation extends navigation_node {
|
||||
$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)) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user