Skip to content

Commit

Permalink
MDL-40600 core_courseformat: duplicate a named section with copy
Browse files Browse the repository at this point in the history
When a named section is duplicated, the name must have a (copy) particle
to make visible what section is the original and what is the copy.
  • Loading branch information
ferranrecio authored and alexmorrisnz committed Feb 26, 2023
1 parent f1c4cc7 commit 01d6ba0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion course/format/classes/base.php
Expand Up @@ -1752,7 +1752,11 @@ public function duplicate_section(section_info $originalsection): section_info {
$oldsectioninfo = get_fast_modinfo($course)->get_section_info($originalsection->section);
$newsection = course_create_section($course, $oldsectioninfo->section + 1); // Place new section after existing one.

$newsection->name = $originalsection->name;
if (!empty($originalsection->name)) {
$newsection->name = get_string('duplicatedsection', 'moodle', $originalsection->name);
} else {
$newsection->name = $originalsection->name;
}
$newsection->summary = $originalsection->summary;
$newsection->summaryformat = $originalsection->summaryformat;
$newsection->visible = $originalsection->visible;
Expand Down
10 changes: 9 additions & 1 deletion course/format/tests/behat/duplicate_section.feature
Expand Up @@ -22,5 +22,13 @@ Feature: Duplicate a section
@javascript
Scenario: Duplicate section
Given I open section "1" edit menu
And I click on "Duplicate" "link" in the "Topic 1" "section"
When I click on "Duplicate" "link" in the "Topic 1" "section"
Then I should see "Activity sample 2" in the "Topic 2" "section"

@javascript
Scenario: Duplicate a named section
Given I set the field "Edit topic name" in the "Topic 1" "section" to "New name"
And I should see "New name" in the "New name" "section"
When I open section "1" edit menu
And I click on "Duplicate" "link" in the "New name" "section"
Then I should see "Activity sample 2" in the "New name (copy)" "section"
3 changes: 3 additions & 0 deletions course/upgrade.txt
Expand Up @@ -4,6 +4,9 @@ information provided here is intended especially for developers.
=== 4.2 ===
* course/mod.php now accepts parameter beforemod for adding course modules. It contains the course module id
of an existing course module. The new module is inserted before this module.
* The function duplicate_module() now has two new optional parameters:
- $sectionid to specify section the duplicated course module is placed in
- $changename to disable changing the name of the course module using the 'duplicatedmodule' lang string

=== 4.1 ===
* The function course_modchooser() has been finally deprecated and can not be used anymore. Please use
Expand Down
1 change: 1 addition & 0 deletions lang/en/moodle.php
Expand Up @@ -583,6 +583,7 @@
$string['droptoupload'] = 'Drop files here to upload';
$string['duplicate'] = 'Duplicate';
$string['duplicatedmodule'] = '{$a} (copy)';
$string['duplicatedsection'] = '{$a} (copy)';
$string['edhelpaspellpath'] = 'To use spell-checking within the editor, you MUST have <strong>aspell 0.50</strong> or later installed on your server, and you must specify the correct path to access the aspell binary. On Unix/Linux systems, this path is usually <strong>/usr/bin/aspell</strong>, but it might be something else.';
$string['edhelpbgcolor'] = 'Define the edit area\'s background color.<br />Valid values are, for example: #FFFFFF or white';
$string['edhelpcleanword'] = 'This setting enables or disables Word-specific format filtering.';
Expand Down

0 comments on commit 01d6ba0

Please sign in to comment.