Generate URL in Block

Re: Generate URL in Block

by Darko Miletić -
Number of replies: 0

Ah yes, I forgot that id parameter is actually course module id. So you have two options here:

Alter the link generator to use f parameter instead of id and it would work as is.

    protected function newsforumurl() {
        $result = false;
        if ($forumid = $this->newsforumid()) {
            $result = html_writer::link(
                new moodle_url('/mod/forum/view.php', ['f' => $forumid]),
                "E-mail"
            );
        }
        return $result;
    }


Obtain the course module id.

    protected function newsforumid() {
        global $CFG, $COURSE;
        $result = false;
        $plugins = \core_plugin_manager::instance()->get_enabled_plugins('mod');
        if (isset($plugins['forum'])) {
            require_once($CFG->dirroot . '/mod/forum/lib.php');
            if ($forum = forum_get_course_forum($COURSE->id, 'news')) {
                if ($cm = get_coursemodule_from_id('forum', $forum->id)) {
                    $result = $cm->id;
                }
            }
        }
        return $result;
    }




Average of ratings: Useful (1)