Skip to content

Commit 0a1ad4d

Browse files
committed
Approach 2
1 parent d3ad77e commit 0a1ad4d

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ protected function add_editor_data(stdClass &$data, renderer_base $output): bool
295295
}
296296

297297
if (empty($this->hidecontrols)) {
298-
$controlmenu = new $this->controlmenuclass($this->format, $this->section);
299-
$data->controlmenu = $controlmenu->export_for_template($output);
298+
$data->controlmenu = $this->get_section_action_menu()->export_for_template($output);
300299
}
301300
if (!$this->isstealth) {
302301
$data->cmcontrols = $output->course_section_add_cm_control(
@@ -308,6 +307,17 @@ protected function add_editor_data(stdClass &$data, renderer_base $output): bool
308307
return true;
309308
}
310309

310+
public function get_section_action_menu() {
311+
$sectiondelegate = $this->section->get_component_instance();
312+
if ($sectiondelegate) {
313+
// Allow delegate plugin to modify the available section action menu.
314+
$controlmenu = $sectiondelegate->get_section_action_menu($this->format, $this->controlmenuclass);
315+
} else {
316+
$controlmenu = new $this->controlmenuclass($this->format, $this->section);
317+
}
318+
return $controlmenu;
319+
}
320+
311321
/**
312322
* Add the section format attributes to the data structure.
313323
*

course/format/classes/sectiondelegate.php

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
namespace core_courseformat;
1818

1919
use section_info;
20+
use core_courseformat\base as course_format;
2021

2122
/**
2223
* Section delegate base class.
@@ -77,4 +78,10 @@ protected static function get_delegate_class_name(string $pluginname): ?string {
7778
public static function has_delegate_class(string $pluginname): bool {
7879
return self::get_delegate_class_name($pluginname) !== null;
7980
}
81+
public function get_section_action_menu(
82+
course_format $format,
83+
string $controlmenuclass,
84+
): \templatable {
85+
return new $controlmenuclass($format, $this->sectioninfo);
86+
}
8087
}

course/section.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,21 @@
143143
}
144144

145145
// Add to the header the control menu for the section.
146+
$headingset = false;
146147
if ($format->show_editor()) {
147148
$sectionclass = new \core_courseformat\output\local\content\section($format, $sectioninfo);
148149
$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 {
150+
if (!empty($renderable->controlmenu?->menu)) {
151+
$controlmenuhtml = $renderable->controlmenu->menu;
152+
if (is_string($controlmenuhtml)) {
153+
$PAGE->add_header_action($controlmenuhtml);
154+
$sectionheading = $OUTPUT->render($format->inplace_editable_render_section_name($sectioninfo, false));
155+
$PAGE->set_heading($sectionheading, false, false);
156+
$headingset = true;
157+
}
158+
}
159+
}
160+
if (!$headingset) {
154161
$PAGE->set_heading($sectiontitle);
155162
}
156163

0 commit comments

Comments
 (0)