From f553947bd5fd42d6da76b008e25b9ccfb51b30ac Mon Sep 17 00:00:00 2001 From: ferran Date: Thu, 14 Aug 2025 14:37:04 +0200 Subject: [PATCH] MDL-80295 core_course: mod and modedit compatible with section id --- public/course/mod.php | 10 ++++++++-- public/course/modedit.php | 14 ++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/public/course/mod.php b/public/course/mod.php index fffc8530ab5..2e0e6fbf9a3 100644 --- a/public/course/mod.php +++ b/public/course/mod.php @@ -76,16 +76,22 @@ require_login(); //check if we are adding / editing a module that has new forms using formslib if (!empty($add)) { $id = required_param('id', PARAM_INT); - $section = required_param('section', PARAM_INT); + $sectionid = optional_param('sectionid', null, PARAM_INT); $type = optional_param('type', '', PARAM_ALPHA); $returntomod = optional_param('return', 0, PARAM_BOOL); $beforemod = optional_param('beforemod', 0, PARAM_INT); + if (empty($sectionid)) { + $section = required_param('section', PARAM_INT); + $sectioninfo = get_fast_modinfo($id)->get_section_info($section); + $sectionid = $sectioninfo?->id; + } + $params = [ 'add' => $add, 'type' => $type, 'course' => $id, - 'section' => $section, + 'sectionid' => $sectionid, 'return' => $returntomod, 'beforemod' => $beforemod, ]; diff --git a/public/course/modedit.php b/public/course/modedit.php index 9b8758f7b11..f33dd7988cf 100644 --- a/public/course/modedit.php +++ b/public/course/modedit.php @@ -56,11 +56,17 @@ if (!empty($showonly)) { } if (!empty($add)) { - $section = required_param('section', PARAM_INT); $course = required_param('course', PARAM_INT); + $sectionid = optional_param('sectionid', null, PARAM_INT); + if (empty($sectionid)) { + $sectionnum = required_param('section', PARAM_INT); + } else { + $sectionnum = get_fast_modinfo($course)->get_section_info_by_id($sectionid, MUST_EXIST)->sectionnum; + } + $url->param('add', $add); - $url->param('section', $section); + $url->param('section', $sectionnum); $url->param('course', $course); $PAGE->set_url($url); @@ -70,9 +76,9 @@ if (!empty($add)) { // There is no page for this in the navigation. The closest we'll have is the course section. // If the course section isn't displayed on the navigation this will fall back to the course which // will be the closest match we have. - navigation_node::override_active_url(course_get_url($course, $section)); + navigation_node::override_active_url(course_get_url($course, $sectionnum)); - list($module, $context, $cw, $cm, $data) = prepare_new_moduleinfo_data($course, $add, $section); + [$module, $context, $cw, $cm, $data] = prepare_new_moduleinfo_data($course, $add, $sectionnum); $data->return = 0; if (!is_null($sectionreturn)) { $data->sr = $sectionreturn;