From b3cb1eb18a42b8f44b732ba46e4341d408b4fc3d Mon Sep 17 00:00:00 2001 From: ferran Date: Tue, 29 Apr 2025 11:29:21 +0200 Subject: [PATCH] MDL-84291 format_topics: create courses with default number of sections --- .upgradenotes/MDL-84291-2025042902174752.yml | 8 ++++++ course/format/topics/lib.php | 12 +++------ .../tests/behat/default_sections.feature | 25 +++++++++++++++++++ 3 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 .upgradenotes/MDL-84291-2025042902174752.yml create mode 100644 course/format/topics/tests/behat/default_sections.feature diff --git a/.upgradenotes/MDL-84291-2025042902174752.yml b/.upgradenotes/MDL-84291-2025042902174752.yml new file mode 100644 index 00000000000..a0b2a2efbe7 --- /dev/null +++ b/.upgradenotes/MDL-84291-2025042902174752.yml @@ -0,0 +1,8 @@ +issueNumber: MDL-84291 +notes: + format_topics: + - message: >- + Now the custom sections format won't ask for initial sections on the + creation form. Instead it will use the system number of sections + settings directly. + type: improved diff --git a/course/format/topics/lib.php b/course/format/topics/lib.php index 575280d85ce..8d0d5923156 100644 --- a/course/format/topics/lib.php +++ b/course/format/topics/lib.php @@ -285,17 +285,11 @@ class format_topics extends core_courseformat\base { $elements = parent::create_edit_form_elements($mform, $forsection); if (!$forsection && (empty($COURSE->id) || $COURSE->id == SITEID)) { - // Add "numsections" element to the create course form - it will force new course to be prepopulated - // with empty sections. - // The "Number of sections" option is no longer available when editing course, instead teachers should - // delete and add sections when needed. + // Custom sections are always created with the default number of sections. $courseconfig = get_config('moodlecourse'); - $max = (int)$courseconfig->maxsections; - $element = $mform->addElement('select', 'numsections', get_string('numberweeks'), range(0, $max ?: 52)); + $element = $mform->addElement('hidden', 'numsections'); $mform->setType('numsections', PARAM_INT); - if (is_null($mform->getElementValue('numsections'))) { - $mform->setDefault('numsections', $courseconfig->numsections); - } + $mform->setDefault('numsections', $courseconfig->numsections); array_unshift($elements, $element); } diff --git a/course/format/topics/tests/behat/default_sections.feature b/course/format/topics/tests/behat/default_sections.feature new file mode 100644 index 00000000000..1924e1ea091 --- /dev/null +++ b/course/format/topics/tests/behat/default_sections.feature @@ -0,0 +1,25 @@ +@format @format_topics +Feature: Custom sections are created with the system default number of sections + In order to create courses + As a course creator + I need my courses to be created as the system default number of sections + + @javascript + Scenario: Default number of sections in course creation + Given the following config values are set as admin: + | numsections | 5 | moodlecourse | + When I log in as "admin" + And I navigate to "Courses > Manage courses and categories" in site administration + And I click on "Create new course" "link" + And I expand all fieldsets + And I set the field "Course full name" to "Course 1" + And I set the field "Course short name" to "C1" + And I set the field "Format" to "Custom sections" + Then I should not see "Number of sections" + And I click on "Save and display" "button" + And "[data-for='section'][data-number='1']" "css_element" should exist + And "[data-for='section'][data-number='2']" "css_element" should exist + And "[data-for='section'][data-number='3']" "css_element" should exist + And "[data-for='section'][data-number='4']" "css_element" should exist + And "[data-for='section'][data-number='5']" "css_element" should exist + And "[data-for='section'][data-number='6']" "css_element" should not exist