Skip to content

Commit a109418

Browse files
committed
MDL-80460 course_format: Create section with "New section" name
1 parent 328b48e commit a109418

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

course/editsection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
);
105105

106106
$courseformat = course_get_format($course);
107-
$defaultsectionname = $courseformat->get_default_section_name($section);
107+
$defaultsectionname = $courseformat->get_new_section_name($section->section);
108108

109109
$customdata = [
110110
'cs' => $sectioninfo,

course/format/classes/base.php

+10
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,16 @@ public function get_default_section_name($section) {
552552
return self::get_section_name($section);
553553
}
554554

555+
/**
556+
* Retrieves the name for a new section.
557+
*
558+
* @param int $sectionnum The section number.
559+
* @return string The name for the new section.
560+
*/
561+
public function get_new_section_name(int $sectionnum) {
562+
return $this->get_default_section_name($sectionnum);
563+
}
564+
555565
/**
556566
* Returns the name for the highlighted section.
557567
*

course/format/topics/lang/en/format_topics.php

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
$string['currentsection'] = 'Current section';
2626
$string['hidefromothers'] = 'Hide';
27+
$string['newsection'] = 'New section';
2728
$string['page-course-view-topics'] = 'Any course main page in custom sections format';
2829
$string['page-course-view-topics-x'] = 'Any course page in custom sections format';
2930
$string['pluginname'] = 'Custom sections';

course/format/topics/lib.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function get_section_name($section) {
6868
return format_string($section->name, true,
6969
['context' => context_course::instance($this->courseid)]);
7070
} else {
71-
return $this->get_default_section_name($section);
71+
return $this->get_new_section_name($section->sectionnum);
7272
}
7373
}
7474

@@ -83,6 +83,7 @@ public function get_section_name($section) {
8383
* @return string The default value for the section name.
8484
*/
8585
public function get_default_section_name($section) {
86+
$section = $this->get_section($section);
8687
if ($section->section == 0) {
8788
// Return the general section.
8889
return get_string('section0name', 'format_topics');
@@ -93,6 +94,15 @@ public function get_default_section_name($section) {
9394
}
9495
}
9596

97+
#[Override]
98+
public function get_new_section_name(int $sectionnum) {
99+
if ($sectionnum == 0) {
100+
return get_string('section0name', 'format_topics');
101+
}
102+
103+
return get_string('newsection', 'format_topics');
104+
}
105+
96106
/**
97107
* Generate the title for this section page.
98108
*

course/format/weeks/lib.php

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function get_section_name($section) {
8787
* @return string The default value for the section name.
8888
*/
8989
public function get_default_section_name($section) {
90+
$section = $this->get_section($section);
9091
if ($section->section == 0) {
9192
// Return the general section.
9293
return get_string('section0name', 'format_weeks');

0 commit comments

Comments
 (0)