From 2874b49ce5626f5ae41278e40eed5ec9f2754791 Mon Sep 17 00:00:00 2001 From: Laurent David Date: Thu, 9 Oct 2025 10:31:32 +0200 Subject: [PATCH] MDL-86333 core_course: Fix return url for edit section --- public/course/editsection.php | 8 +++--- public/course/editsection_form.php | 6 +++++ .../local/content/section/controlmenu.php | 1 + .../format/tests/behat/section_page.feature | 25 +++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/public/course/editsection.php b/public/course/editsection.php index 325cd6af3fa..0dbd942baee 100644 --- a/public/course/editsection.php +++ b/public/course/editsection.php @@ -31,6 +31,7 @@ $id = required_param('id', PARAM_INT); // course_sections.id $sectionreturn = optional_param('sr', null, PARAM_INT); $deletesection = optional_param('delete', 0, PARAM_BOOL); $showonly = optional_param('showonly', 0, PARAM_TAGLIST); +$returnurl = optional_param('returnurl', null, PARAM_LOCALURL); $returnparams = []; $params = ['id' => $id]; @@ -67,7 +68,7 @@ if ($deletesection) { if ($confirm) { course_delete_section($course, $sectioninfo, true, true); $courseurl = course_get_url($course, $sectioninfo->section - 1, $returnparams); - redirect($courseurl); + redirect($returnurl ?? $courseurl); } else { if (get_string_manager()->string_exists('deletesection', 'format_' . $course->format)) { $strdelete = get_string('deletesection', 'format_' . $course->format); @@ -116,6 +117,7 @@ $customdata = [ 'editoroptions' => $editoroptions, 'defaultsectionname' => $defaultsectionname, 'showonly' => $showonly, + 'returnurl' => $returnurl, ]; $mform = $courseformat->editsection_form($PAGE->url, $customdata); @@ -133,7 +135,7 @@ if (!empty($showonly)) { if ($mform->is_cancelled()){ // Form cancelled, return to course. - redirect(course_get_url($course, $section, $returnparams)); + redirect($returnurl ?? course_get_url($course, $section, $returnparams)); } else if ($data = $mform->get_data()) { // Data submitted and validated, update and return to course. @@ -149,7 +151,7 @@ if ($mform->is_cancelled()){ course_update_section($course, $section, $data); $PAGE->navigation->clear_cache(); - redirect(course_get_url($course, $section, $returnparams)); + redirect($returnurl ?? course_get_url($course, $section, $returnparams)); } // The edit form is displayed for the first time or if there was validation error on the previous step. diff --git a/public/course/editsection_form.php b/public/course/editsection_form.php index 5263b02cc53..12e453b454a 100644 --- a/public/course/editsection_form.php +++ b/public/course/editsection_form.php @@ -22,6 +22,7 @@ class editsection_form extends moodleform { $mform = $this->_form; $course = $this->_customdata['course']; $sectioninfo = $this->_customdata['cs']; + $returnurl = $this->_customdata['returnurl']; $mform->addElement('header', 'generalhdr', get_string('general')); @@ -50,6 +51,11 @@ class editsection_form extends moodleform { $mform->addElement('hidden', 'course', 0); $mform->setType('course', PARAM_INT); + if ($returnurl) { + $mform->addElement('hidden', 'returnurl', $returnurl); + $mform->setType('returnurl', PARAM_LOCALURL); + } + // additional fields that course format has defined $courseformat = course_get_format($course); $formatoptions = $courseformat->section_format_options(true); diff --git a/public/course/format/classes/output/local/content/section/controlmenu.php b/public/course/format/classes/output/local/content/section/controlmenu.php index 0f7de911eb9..75f2a3eb663 100644 --- a/public/course/format/classes/output/local/content/section/controlmenu.php +++ b/public/course/format/classes/output/local/content/section/controlmenu.php @@ -141,6 +141,7 @@ class controlmenu extends basecontrolmenu { [ 'id' => $this->section->id, 'sr' => $this->section->sectionnum, + 'returnurl' => $this->baseurl, ] ); diff --git a/public/course/format/tests/behat/section_page.feature b/public/course/format/tests/behat/section_page.feature index f8bd4f93f2d..b80c66713f5 100644 --- a/public/course/format/tests/behat/section_page.feature +++ b/public/course/format/tests/behat/section_page.feature @@ -129,3 +129,28 @@ Feature: Single section course page Then I should not see "Section 1" # The user should be redirected to the course page. And I should see "General" in the "page" "region" + + @javascript + Scenario: When I edit a section from the section page, after saving I stay in the section page + Given I am on the "Course 1 > Section 1" "course > section" page + And I turn editing mode on + And I choose the "Edit settings" item in the "Edit" action menu of the "page-header" "region" + When I set the field "Section name" to "New name for section 1" + And I press "Save changes" + Then I should see "New name for section 1" in the "page-header" "region" + And I should see "Activity sample 1.1" + And I should see "Activity sample 1.2" + And I should see "Activity sample 1.3" + And I should not see "Activity sample 2.1" in the "region-main" "region" + And I should not see "Activity sample 2.1" in the "region-main" "region" + + @javascript + Scenario: When I edit a section from the course page, after saving I stay in the course page + Given I turn editing mode on + And I open section "1" edit menu + And I choose "Edit settings" in the open action menu + When I set the field "Section name" to "New name for section 1" + And I press "Save changes" + Then I should see "Course 1" in the "page-header" "region" + And I should see "General" in the "region-main" "region" + And I should see "New name for section 1" in the "region-main" "region"