From 2738e583047ea56569ef48f3bcd33d1bc7473ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikel=20Mart=C3=ADn?= Date: Tue, 27 Aug 2024 15:50:45 +0200 Subject: [PATCH] MDL-82617 mod_subsection: Redirect from modedit to sectionedit page When accessing mod_subsection edit form, redirect to section edit page of the delegated section. --- mod/subsection/lib.php | 2 +- mod/subsection/mod_form.php | 52 ++++++++++++------- .../tests/behat/subsection_visibility.feature | 5 +- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/mod/subsection/lib.php b/mod/subsection/lib.php index b3e259bb69a..0ec8838b564 100644 --- a/mod/subsection/lib.php +++ b/mod/subsection/lib.php @@ -37,7 +37,7 @@ function subsection_supports($feature) { FEATURE_GROUPS => false, FEATURE_GROUPINGS => false, FEATURE_MOD_INTRO => false, - FEATURE_COMPLETION_TRACKS_VIEWS => true, + FEATURE_COMPLETION_TRACKS_VIEWS => false, FEATURE_GRADE_HAS_GRADE => false, FEATURE_GRADE_OUTCOMES => false, FEATURE_BACKUP_MOODLE2 => true, diff --git a/mod/subsection/mod_form.php b/mod/subsection/mod_form.php index 2cd1927b4bc..002d56df076 100644 --- a/mod/subsection/mod_form.php +++ b/mod/subsection/mod_form.php @@ -26,6 +26,8 @@ defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot.'/course/moodleform_mod.php'); +use mod_subsection\manager; + /** * Module instance settings form. * @@ -41,27 +43,37 @@ class mod_subsection_mod_form extends moodleform_mod { public function definition() { global $CFG; - $mform = $this->_form; - - // Adding the "general" fieldset, where all the common settings are shown. - $mform->addElement('header', 'general', get_string('general', 'form')); - - // Adding the standard "name" field. - $mform->addElement('text', 'name', get_string('subsectionname', 'mod_subsection'), ['size' => '64']); - - if (!empty($CFG->formatstringstriptags)) { - $mform->setType('name', PARAM_TEXT); + // Showing edit form. Redirect to the edit section page. + if (!empty($this->current->instance)) { + $manager = manager::create_from_id($this->current->course, $this->current->id); + $editurl = new moodle_url('/course/editsection.php', ['id' => $manager->get_delegated_section_info()->id]); + redirect($editurl->out()); } else { - $mform->setType('name', PARAM_CLEANHTML); + $mform = $this->_form; + + // Adding the "general" fieldset, where all the common settings are shown. + $mform->addElement('header', 'general', get_string('general', 'form')); + + // Adding the standard "name" field. + $mform->addElement('text', 'name', get_string('subsectionname', 'mod_subsection'), ['size' => '64']); + + if (!empty($CFG->formatstringstriptags)) { + $mform->setType('name', PARAM_TEXT); + } else { + $mform->setType('name', PARAM_CLEANHTML); + } + + $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); + + // Add standard elements. + $this->standard_coursemodule_elements(); + + // Add standard buttons. + $this->add_action_buttons(); + + // Show only general and restrictions form sections. + $mform->filter_shown_headers(['general', 'availabilityconditionsheader']); } - - $mform->addRule('name', null, 'required', null, 'client'); - $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); - - // Add standard elements. - $this->standard_coursemodule_elements(); - - // Add standard buttons. - $this->add_action_buttons(); } } diff --git a/mod/subsection/tests/behat/subsection_visibility.feature b/mod/subsection/tests/behat/subsection_visibility.feature index 5d2c5b7ef23..f885a123a9e 100644 --- a/mod/subsection/tests/behat/subsection_visibility.feature +++ b/mod/subsection/tests/behat/subsection_visibility.feature @@ -29,8 +29,9 @@ Feature: Subsection visibility should work as a module When I hide section "Section 1" And I should see "Hidden from students" in the "Section 1" "section" # We cannot use generators because they don't check the parent section visibility. - And I add a subsection activity to course "Course 1" section "1" and I fill the form with: - | Name | Subsection 1 | + And I add a subsection activity to course "Course 1" section "1" + And I set the field "Name" to "Subsection 1" + And I press "Save and return to course" And I add a assign activity to course "Course 1" section "1" and I fill the form with: | Assignment name | Hidden assignment name | | ID number | assign1 |