MDL-86333 core_course: Fix return url for edit section
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -141,6 +141,7 @@ class controlmenu extends basecontrolmenu {
|
||||
[
|
||||
'id' => $this->section->id,
|
||||
'sr' => $this->section->sectionnum,
|
||||
'returnurl' => $this->baseurl,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user