Skip to content

Commit ee21045

Browse files
committed
MDL-80249 course: Hide secondary menu and add breadcrumb to section page
1 parent 328b48e commit ee21045

File tree

23 files changed

+194
-104
lines changed

23 files changed

+194
-104
lines changed

blocks/section_links/block_section_links.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ public function init() {
4444
* @return array
4545
*/
4646
public function applicable_formats() {
47-
return array(
47+
return [
4848
'course-view-weeks' => true,
49-
'course-view-topics' => true
50-
);
49+
'course-view-topics' => true,
50+
'section-view-weeks' => true,
51+
'section-view-topics' => true,
52+
];
5153
}
5254

5355
/**
@@ -179,5 +181,3 @@ public function get_config_for_external() {
179181
];
180182
}
181183
}
182-
183-

course/format/classes/base.php

+10
Original file line numberDiff line numberDiff line change
@@ -2028,4 +2028,14 @@ public function duplicate_section(section_info $originalsection): section_info {
20282028
public function get_required_jsfiles(): array {
20292029
return [];
20302030
}
2031+
2032+
/**
2033+
* Determines whether section items can be removed from the navigation, just like the breadcrumb feature seen on activity pages.
2034+
* By default, it returns false but can be overridden by the course format to change the behaviour.
2035+
*
2036+
* @return bool True if sections can be removed, false otherwise.
2037+
*/
2038+
public function can_sections_be_removed_from_navigation(): bool {
2039+
return false;
2040+
}
20312041
}

course/format/classes/output/local/content/section/controlmenu.php

+16-8
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function export_for_template(\renderer_base $output): stdClass {
119119
* @return array of edit control items
120120
*/
121121
public function section_control_items() {
122-
global $USER;
122+
global $USER, $PAGE;
123123

124124
$format = $this->format;
125125
$section = $this->section;
@@ -135,13 +135,18 @@ public function section_control_items() {
135135
$baseurl = course_get_url($course, $sectionreturn);
136136
$baseurl->param('sesskey', sesskey());
137137

138-
$controls['view'] = [
139-
'url' => new moodle_url('/course/section.php', ['id' => $section->id]),
140-
'icon' => 'i/viewsection',
141-
'name' => get_string('view'),
142-
'pixattr' => ['class' => ''],
143-
'attr' => ['class' => 'icon view'],
144-
];
138+
$controls = [];
139+
140+
// Only show the view link if we are not already in the section view page.
141+
if ($PAGE->pagetype !== 'section-view-' . $course->format) {
142+
$controls['view'] = [
143+
'url' => new moodle_url('/course/section.php', ['id' => $section->id]),
144+
'icon' => 'i/viewsection',
145+
'name' => get_string('view'),
146+
'pixattr' => ['class' => ''],
147+
'attr' => ['class' => 'icon view'],
148+
];
149+
}
145150

146151
if (!$isstealth && has_capability('moodle/course:update', $coursecontext, $user)) {
147152
$params = ['id' => $section->id];
@@ -177,6 +182,9 @@ public function section_control_items() {
177182

178183
if ($section->section) {
179184
$url = clone($baseurl);
185+
if (!is_null($sectionreturn)) {
186+
$url->param('sectionid', $format->get_sectionid());
187+
}
180188
if (!$isstealth) {
181189
if (has_capability('moodle/course:sectionvisibility', $coursecontext, $user)) {
182190
$strhidefromothers = get_string('hidefromothers', 'format_' . $course->format);

course/format/templates/local/content/section.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
}}
8989
<li id="section-{{num}}"
9090
class="section course-section main {{#onlysummary}} section-summary {{/onlysummary}} clearfix
91-
{{#ishidden}} hidden {{/ishidden}} {{#iscurrent}} current {{/iscurrent}}
91+
{{#ishidden}} hidden {{/ishidden}} {{#iscurrent}}{{^displayonesection}} current {{/displayonesection}}{{/iscurrent}}
9292
{{#isstealth}} orphaned {{/isstealth}}"
9393
data-sectionid="{{num}}"
9494
data-sectionreturnid="{{sectionreturnid}}"

course/format/templates/local/content/section/content.mustache

+24-20
Original file line numberDiff line numberDiff line change
@@ -123,29 +123,33 @@
123123
{{/displayonesection}}
124124
{{/collapsemenu}}
125125
{{#controlmenu}}
126-
{{$ core_courseformat/local/content/section/controlmenu }}
127-
{{> core_courseformat/local/content/section/controlmenu }}
128-
{{/ core_courseformat/local/content/section/controlmenu }}
126+
{{^displayonesection}}
127+
{{$ core_courseformat/local/content/section/controlmenu }}
128+
{{> core_courseformat/local/content/section/controlmenu }}
129+
{{/ core_courseformat/local/content/section/controlmenu }}
130+
{{/displayonesection}}
129131
{{/controlmenu}}
130132
{{#header}}
131133
{{#headerdisplaymultipage}}
132-
{{^controlmenu}}
133-
<div class="section_goto bulk-hidden ml-auto" data-sectionid="{{id}}">
134-
<a href="{{{url}}}"
135-
class="btn btn-icon d-flex align-items-center justify-content-center icon-no-margin"
136-
title="{{#str}}gotosection, course, {{name}}{{/str}}">
137-
<span class="dir-rtl-hide">
138-
{{#pix}}t/right, moodle{{/pix}}
139-
</span>
140-
<span class="dir-ltr-hide">
141-
{{#pix}}t/left, moodle, {{#str}}gotosection, course, {{name}}{{/str}}{{/pix}}
142-
</span>
143-
<span class="sr-only">
144-
{{#str}}gotosection, course, {{name}}{{/str}}
145-
</span>
146-
</a>
147-
</div>
148-
{{/controlmenu}}
134+
{{^displayonesection}}
135+
{{^controlmenu}}
136+
<div class="section_goto bulk-hidden ml-auto" data-sectionid="{{id}}">
137+
<a href="{{{url}}}"
138+
class="btn btn-icon d-flex align-items-center justify-content-center icon-no-margin"
139+
title="{{#str}}gotosection, course, {{name}}{{/str}}">
140+
<span class="dir-rtl-hide">
141+
{{#pix}}t/right, moodle{{/pix}}
142+
</span>
143+
<span class="dir-ltr-hide">
144+
{{#pix}}t/left, moodle, {{#str}}gotosection, course, {{name}}{{/str}}{{/pix}}
145+
</span>
146+
<span class="sr-only">
147+
{{#str}}gotosection, course, {{name}}{{/str}}
148+
</span>
149+
</a>
150+
</div>
151+
{{/controlmenu}}
152+
{{/displayonesection}}
149153
{{/headerdisplaymultipage}}
150154
{{/header}}
151155
</div>

course/format/templates/local/content/section/header.mustache

+5-8
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
{{/ core_courseformat/local/content/section/bulkselect }}
3737
{{/sectionbulk}}
3838
{{#headerdisplaymultipage}}
39-
<h3 id="sectionid-{{id}}-title" class="sectionname">
40-
{{{title}}}
41-
</h3>
39+
{{^displayonesection}}
40+
<h3 id="sectionid-{{id}}-title" class="sectionname">
41+
{{{title}}}
42+
</h3>
43+
{{/displayonesection}}
4244
{{/headerdisplaymultipage}}
4345
{{^headerdisplaymultipage}}
4446
{{#sitehome}}
@@ -47,11 +49,6 @@
4749
</h2>
4850
{{/sitehome}}
4951
{{^sitehome}}
50-
{{#displayonesection}}
51-
<h3 id="sectionid-{{id}}-title" class="sectionname">
52-
{{{title}}}
53-
</h3>
54-
{{/displayonesection}}
5552
{{^displayonesection}}
5653
<div class="d-flex align-items-start position-relative">
5754
<a role="button"

course/format/tests/base_test.php

+22
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,24 @@ public static function set_sectionnum_provider(): array {
880880
];
881881
}
882882

883+
/**
884+
* Test can_sections_be_removed_from_navigation().
885+
*
886+
* @covers ::can_sections_be_removed_from_navigation
887+
*/
888+
public function test_can_sections_be_removed_from_navigation(): void {
889+
$this->resetAfterTest();
890+
891+
$generator = $this->getDataGenerator();
892+
893+
$course = $generator->create_course();
894+
$format = course_get_format($course);
895+
$this->assertFalse($format->can_sections_be_removed_from_navigation());
896+
897+
$course = $generator->create_course(['format' => 'testformatsections']);
898+
$format = course_get_format($course);
899+
$this->assertTrue($format->can_sections_be_removed_from_navigation());
900+
}
883901
}
884902

885903
/**
@@ -923,6 +941,10 @@ class format_testformatsections extends core_courseformat\base {
923941
public function uses_sections() {
924942
return true;
925943
}
944+
945+
public function can_sections_be_removed_from_navigation(): bool {
946+
return true;
947+
}
926948
}
927949

928950
/**

course/format/tests/behat/section_page.feature

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ Feature: Single section course page
7373
But I am on "Course 1" course homepage
7474
And I open section "0" edit menu
7575
And I click on "View" "link" in the "General" "section"
76-
And I should see "General" in the "region-main" "region"
76+
And I should see "General" in the "page" "region"
7777
And I should see "Activity sample 0.1" in the "region-main" "region"
7878
And I should not see "Activity sample 1.1" in the "region-main" "region"
7979
And I should not see "Activity sample 1.2" in the "region-main" "region"
8080
And I should not see "Activity sample 1.3" in the "region-main" "region"
8181
And I should not see "Activity sample 2.1" in the "region-main" "region"
8282
And I should not see "Activity sample 2.1" in the "region-main" "region"
8383
# The section viewed has been trigered.
84+
And I am on "Course 1" course homepage
8485
And I navigate to "Reports > Live logs" in current page administration
8586
And I should see "Section viewed"

course/format/topics/classes/output/courseformat/content/section/controlmenu.php

+6
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ protected function get_highlight_control(): array {
110110
$format = $this->format;
111111
$section = $this->section;
112112
$course = $format->get_course();
113+
$sectionreturn = $format->get_sectionnum();
113114
$url = $this->get_course_url();
115+
if (!is_null($sectionreturn)) {
116+
$url->param('sectionid', $format->get_sectionid());
117+
}
114118

115119
$highlightoff = get_string('highlightoff');
116120
$highlighton = get_string('highlight');
@@ -125,6 +129,7 @@ protected function get_highlight_control(): array {
125129
'attr' => [
126130
'class' => 'editing_highlight',
127131
'data-action' => 'sectionUnhighlight',
132+
'data-sectionreturn' => $sectionreturn,
128133
'data-id' => $section->id,
129134
'data-swapname' => $highlighton,
130135
'data-swapicon' => 'i/marker',
@@ -140,6 +145,7 @@ protected function get_highlight_control(): array {
140145
'attr' => [
141146
'class' => 'editing_highlight',
142147
'data-action' => 'sectionHighlight',
148+
'data-sectionreturn' => $sectionreturn,
143149
'data-id' => $section->id,
144150
'data-swapname' => $highlightoff,
145151
'data-swapicon' => 'i/marked',

course/format/topics/tests/behat/edit_delete_sections.feature

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Feature: Sections can be edited and deleted in custom sections format
3333
When I edit the section "0" and I fill the form with:
3434
| Custom | 1 |
3535
| New value for Section name | This is the general section |
36-
Then I should see "This is the general section" in the "This is the general section" "section"
36+
Then I should see "This is the general section" in the "page" "region"
3737

3838
Scenario: View the default name of the second section in custom sections format
3939
When I edit the section "2"
@@ -43,13 +43,13 @@ Feature: Sections can be edited and deleted in custom sections format
4343
Scenario: Edit section summary in custom sections format
4444
When I edit the section "2" and I fill the form with:
4545
| Description | Welcome to section 2 |
46-
Then I should see "Welcome to section 2" in the "Topic 2" "section"
46+
Then I should see "Welcome to section 2" in the "page" "region"
4747

4848
Scenario: Edit section default name in custom sections format
4949
When I edit the section "2" and I fill the form with:
5050
| Custom | 1 |
5151
| New value for Section name | This is the second topic |
52-
Then I should see "This is the second topic" in the "This is the second topic" "section"
52+
Then I should see "This is the second topic" in the "page" "region"
5353
And I should not see "Topic 2" in the "region-main" "region"
5454

5555
@javascript

course/format/weeks/tests/behat/edit_delete_sections.feature

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Feature: Sections can be edited and deleted in weekly sections format
3232
When I edit the section "0" and I fill the form with:
3333
| Custom | 1 |
3434
| New value for Section name | This is the general section |
35-
Then I should see "This is the general section" in the "This is the general section" "section"
35+
Then I should see "This is the general section" in the "page" "region"
3636

3737
Scenario: View the default name of the second section in weeks format
3838
When I edit the section "2"
@@ -42,14 +42,14 @@ Feature: Sections can be edited and deleted in weekly sections format
4242
Scenario: Edit section summary in weeks format
4343
When I edit the section "2" and I fill the form with:
4444
| Description | Welcome to section 2 |
45-
Then I should see "Welcome to section 2" in the "8 May - 14 May" "section"
45+
Then I should see "Welcome to section 2" in the "page" "region"
4646

4747
Scenario: Edit section default name in weeks format
4848
Given I should see "8 May - 14 May" in the "8 May - 14 May" "section"
4949
When I edit the section "2" and I fill the form with:
5050
| Custom | 1 |
5151
| New value for Section name | This is the second week |
52-
Then I should see "This is the second week" in the "This is the second week" "section"
52+
Then I should see "This is the second week" in the "page" "region"
5353
And I should not see "8 May - 14 May"
5454

5555
@javascript

course/section.php

+21-8
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
// Fix course format if it is no longer installed.
4747
$format = course_get_format($course);
4848
$course->format = $format->get_format();
49+
$format->set_sectionid($section->id);
4950

5051
// When the course format doesn't support sections, redirect to course page.
5152
if (!course_format_uses_sections($course->format)) {
@@ -62,18 +63,18 @@
6263

6364
// Must set layout before getting section info. See MDL-47555.
6465
$PAGE->set_pagelayout('course');
65-
$PAGE->add_body_class('limitedwidth');
66+
$PAGE->add_body_classes(['limitedwidth', 'single-section-page']);
6667

6768
// Get section details and check it exists.
6869
$modinfo = get_fast_modinfo($course);
69-
$coursesections = $modinfo->get_section_info($section->section, MUST_EXIST);
70+
$sectioninfo = $modinfo->get_section_info($section->section, MUST_EXIST);
7071

7172
// Check user is allowed to see it.
72-
if (!$coursesections->uservisible) {
73+
if (!$sectioninfo->uservisible) {
7374
// Check if coursesection has conditions affecting availability and if
7475
// so, output availability info.
75-
if ($coursesections->visible && $coursesections->availableinfo) {
76-
$sectionname = get_section_name($course, $coursesections);
76+
if ($sectioninfo->visible && $sectioninfo->availableinfo) {
77+
$sectionname = get_section_name($course, $sectioninfo);
7778
$message = get_string('notavailablecourse', '', $sectionname);
7879
redirect(course_get_url($course), $message, null, \core\output\notification::NOTIFY_ERROR);
7980
} else {
@@ -84,7 +85,7 @@
8485
}
8586
}
8687

87-
$PAGE->set_pagetype('course-view-' . $course->format);
88+
$PAGE->set_pagetype('section-view-' . $course->format);
8889
$PAGE->set_other_editing_capability('moodle/course:update');
8990
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
9091
$PAGE->set_other_editing_capability('moodle/course:activityvisibility');
@@ -141,7 +142,20 @@
141142
$PAGE->add_header_action($bulkbutton);
142143
}
143144

144-
$PAGE->set_heading($course->fullname);
145+
// Add to the header the control menu for the section.
146+
if ($format->show_editor()) {
147+
$sectionclass = new \core_courseformat\output\local\content\section($format, $sectioninfo);
148+
$renderable = $sectionclass->export_for_template($renderer);
149+
$controlmenuhtml = $renderable->controlmenu->menu;
150+
$PAGE->add_header_action($controlmenuhtml);
151+
$sectionheading = $OUTPUT->render($format->inplace_editable_render_section_name($sectioninfo, false));
152+
$PAGE->set_heading($sectionheading, false, false);
153+
} else {
154+
$PAGE->set_heading($sectiontitle);
155+
}
156+
157+
$PAGE->set_secondary_navigation(false);
158+
145159
echo $OUTPUT->header();
146160

147161
// Show communication room status notification.
@@ -168,7 +182,6 @@
168182
// Include course AJAX.
169183
include_course_ajax($course, $modinfo->get_used_module_names());
170184

171-
$format->set_sectionid($section->id);
172185
$outputclass = $format->get_output_classname('content');
173186
$widget = new $outputclass($format);
174187
echo $renderer->render($widget);

0 commit comments

Comments
 (0)