diff --git a/course/editsection_form.php b/course/editsection_form.php index dfbbff2eb19..264ae96ac0d 100644 --- a/course/editsection_form.php +++ b/course/editsection_form.php @@ -20,27 +20,16 @@ class editsection_form extends moodleform { $mform = $this->_form; $course = $this->_customdata['course']; + $sectioninfo = $this->_customdata['cs']; $mform->addElement('header', 'generalhdr', get_string('general')); - $elementgroup = array(); - $elementgroup[] = $mform->createElement('text', 'name', '', array('size' => '30', 'maxlength' => '255')); - - // Get default section name. - $defaultsectionname = $this->_customdata['defaultsectionname']; - if ($defaultsectionname) { - $defaultsectionname = ' [' . $defaultsectionname . ']'; - } - - $elementgroup[] = $mform->createElement('checkbox', 'usedefaultname', '', - get_string('sectionusedefaultname') . $defaultsectionname); - - $mform->addGroup($elementgroup, 'name_group', get_string('sectionname'), ' ', false); - $mform->addGroupRule('name_group', array('name' => array(array(get_string('maximumchars', '', 255), 'maxlength', 255)))); - - $mform->setDefault('usedefaultname', true); - $mform->setType('name', PARAM_TEXT); - $mform->disabledIf('name','usedefaultname','checked'); + $mform->addElement('defaultcustom', 'name', get_string('sectionname'), [ + 'defaultvalue' => $this->_customdata['defaultsectionname'], + 'customvalue' => $sectioninfo->name, + ], ['size' => 30, 'maxlength' => 255]); + $mform->setDefault('name', false); + $mform->addGroupRule('name', array('name' => array(array(get_string('maximumchars', '', 255), 'maxlength', 255)))); /// Prepare course and the editor @@ -98,7 +87,9 @@ class editsection_form extends moodleform { $editoroptions = $this->_customdata['editoroptions']; $default_values = file_prepare_standard_editor($default_values, 'summary', $editoroptions, $editoroptions['context'], 'course', 'section', $default_values->id); - $default_values->usedefaultname = (strval($default_values->name) === ''); + if (strval($default_values->name) === '') { + $default_values->name = false; + } parent::set_data($default_values); } @@ -113,7 +104,7 @@ class editsection_form extends moodleform { if ($data !== null) { $editoroptions = $this->_customdata['editoroptions']; // Set name as an empty string if use default section name is checked. - if (!empty($data->usedefaultname)) { + if ($data->name === false) { $data->name = ''; } $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, diff --git a/course/format/topics/tests/behat/edit_delete_sections.feature b/course/format/topics/tests/behat/edit_delete_sections.feature index 49023a54996..1c836478c7b 100644 --- a/course/format/topics/tests/behat/edit_delete_sections.feature +++ b/course/format/topics/tests/behat/edit_delete_sections.feature @@ -26,19 +26,21 @@ Feature: Sections can be edited and deleted in topics format Scenario: View the default name of the general section in topics format When I click on "Edit section" "link" in the "li#section-0" "css_element" - Then I should see "Use default section name [General]" + Then the field "Custom" matches value "0" + And the field "New value for Section name" matches value "General" Scenario: Edit the default name of the general section in topics format When I click on "Edit section" "link" in the "li#section-0" "css_element" And I set the following fields to these values: - | Use default section name | 0 | - | name | This is the general section | + | Custom | 1 | + | New value for Section name | This is the general section | And I press "Save changes" Then I should see "This is the general section" in the "li#section-0" "css_element" Scenario: View the default name of the second section in topics format When I click on "Edit topic" "link" in the "li#section-2" "css_element" - Then I should see "Use default section name [Topic 2]" + Then the field "Custom" matches value "0" + And the field "New value for Section name" matches value "Topic 2" Scenario: Edit section summary in topics format When I edit the section "2" and I fill the form with: @@ -47,8 +49,8 @@ Feature: Sections can be edited and deleted in topics format Scenario: Edit section default name in topics format When I edit the section "2" and I fill the form with: - | Use default section name | 0 | - | name | This is the second topic | + | Custom | 1 | + | New value for Section name | This is the second topic | Then I should see "This is the second topic" in the "li#section-2" "css_element" And I should not see "Topic 2" in the "li#section-2" "css_element" diff --git a/course/format/weeks/tests/behat/edit_delete_sections.feature b/course/format/weeks/tests/behat/edit_delete_sections.feature index 5d2150cf4be..6269da09f5a 100644 --- a/course/format/weeks/tests/behat/edit_delete_sections.feature +++ b/course/format/weeks/tests/behat/edit_delete_sections.feature @@ -26,19 +26,21 @@ Feature: Sections can be edited and deleted in weeks format Scenario: View the default name of the general section in weeks format When I click on "Edit section" "link" in the "li#section-0" "css_element" - Then I should see "Use default section name [General]" + Then the field "Custom" matches value "0" + And the field "New value for Section name" matches value "General" Scenario: Edit the default name of the general section in weeks format When I click on "Edit section" "link" in the "li#section-0" "css_element" And I set the following fields to these values: - | Use default section name | 0 | - | name | This is the general section | + | Custom | 1 | + | New value for Section name | This is the general section | And I press "Save changes" Then I should see "This is the general section" in the "li#section-0" "css_element" Scenario: View the default name of the second section in weeks format When I click on "Edit week" "link" in the "li#section-2" "css_element" - Then I should see "Use default section name [8 May - 14 May]" + Then the field "Custom" matches value "0" + And the field "New value for Section name" matches value "8 May - 14 May" Scenario: Edit section summary in weeks format When I click on "Edit week" "link" in the "li#section-2" "css_element" @@ -51,8 +53,8 @@ Feature: Sections can be edited and deleted in weeks format Given I should see "8 May - 14 May" in the "li#section-2" "css_element" When I click on "Edit week" "link" in the "li#section-2" "css_element" And I set the following fields to these values: - | Use default section name | 0 | - | name | This is the second week | + | Custom | 1 | + | New value for Section name | This is the second week | And I press "Save changes" Then I should see "This is the second week" in the "li#section-2" "css_element" And I should not see "8 May - 14 May" in the "li#section-2" "css_element" diff --git a/lang/en/deprecated.txt b/lang/en/deprecated.txt index 306fdc00a2e..fcf01727489 100644 --- a/lang/en/deprecated.txt +++ b/lang/en/deprecated.txt @@ -61,4 +61,5 @@ timesent,core_message userssearchresults,core_message loginpasswordautocomplete,core_admin loginpasswordautocomplete_help,core_admin -deletecomment,core \ No newline at end of file +deletecomment,core +sectionusedefaultname,core diff --git a/lang/en/moodle.php b/lang/en/moodle.php index e18c1727e42..839580f0cce 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -1649,7 +1649,6 @@ $string['section'] = 'Section'; $string['sectionactionnotsupported'] = 'Section action "{$a}" is not supported here'; $string['sectionname'] = 'Section name'; $string['sections'] = 'Sections'; -$string['sectionusedefaultname'] = 'Use default section name'; $string['seealsostats'] = 'See also: stats'; $string['select'] = 'Select'; $string['selectacategory'] = 'Please select a category'; @@ -2063,4 +2062,5 @@ $string['modchooserenable'] = 'Activity chooser on'; $string['modchooserdisable'] = 'Activity chooser off'; // Deprecated since Moodle 3.3. -$string['deletecomment'] = 'Delete this comment'; \ No newline at end of file +$string['deletecomment'] = 'Delete this comment'; +$string['sectionusedefaultname'] = 'Use default section name';