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.
This commit is contained in:
Mikel Martín
2024-09-02 10:15:52 +02:00
parent 072fb90384
commit 2738e58304
3 changed files with 36 additions and 23 deletions
+1 -1
View File
@@ -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,
+32 -20
View File
@@ -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();
}
}
@@ -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 |