Skip to content

Commit 5aac73b

Browse files
committed
Approach 1
1 parent d3ad77e commit 5aac73b

File tree

4 files changed

+57
-24
lines changed

4 files changed

+57
-24
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class controlmenu implements named_templatable, renderable {
5151
/** @var section_info the section object */
5252
private $section;
5353

54-
/** @var action_menu the activity aciton menu */
54+
/** @var action_menu the activity action menu */
5555
protected $menu;
5656

5757
/** @var cm_info the course module instance */
@@ -65,7 +65,7 @@ class controlmenu implements named_templatable, renderable {
6565
*
6666
* @param course_format $format the course format
6767
* @param section_info $section the section info
68-
* @param cm_info $mod the course module ionfo
68+
* @param cm_info $mod the course module info
6969
* @param array $displayoptions optional extra display options
7070
*/
7171
public function __construct(course_format $format, section_info $section, cm_info $mod, array $displayoptions = []) {
@@ -106,11 +106,11 @@ public function export_for_template(\renderer_base $output): stdClass {
106106
}
107107

108108
/**
109-
* Generate the aciton menu element.
109+
* Generate the action menu element.
110110
*
111111
* This method is public in case some block needs to modify the menu before output it.
112112
* @param \renderer_base $output typically, the renderer that's calling this function
113-
* @return aciton_menu the activity action menu
113+
* @return action_menu the activity action menu
114114
*/
115115
public function get_action_menu(\renderer_base $output): ?action_menu {
116116

@@ -134,7 +134,7 @@ public function get_action_menu(\renderer_base $output): ?action_menu {
134134
// Prioritise the menu ahead of all other actions.
135135
$menu->prioritise = true;
136136

137-
$ownerselector = $displayoptions['ownerselector'] ?? '#module-' . $mod->id;
137+
$ownerselector = $this->displayoptions['ownerselector'] ?? '#module-' . $mod->id;
138138
$menu->set_owner_selector($ownerselector);
139139

140140
foreach ($controls as $control) {
@@ -158,7 +158,7 @@ public function get_action_menu(\renderer_base $output): ?action_menu {
158158
*
159159
* @return array of edit control items
160160
*/
161-
protected function cm_control_items() {
161+
public function cm_control_items() {
162162
$format = $this->format;
163163
$mod = $this->mod;
164164
$sectionreturn = $format->get_sectionnum();

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

+26-13
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ public function export_for_template(\renderer_base $output): stdClass {
7474

7575
$section = $this->section;
7676

77-
$controls = $this->section_control_items();
77+
$sectiondelegate = $section->get_component_instance();
78+
if ($sectiondelegate) {
79+
// Allow delegate plugin to modify the available section actions.
80+
$controls = $sectiondelegate->get_section_options($this->format, $this);
81+
} else {
82+
$controls = $this->section_control_items();
83+
}
7884

7985
if (empty($controls)) {
8086
return new stdClass();
@@ -85,18 +91,25 @@ public function export_for_template(\renderer_base $output): stdClass {
8591
$menu->set_kebab_trigger(get_string('edit'));
8692
$menu->attributes['class'] .= ' section-actions';
8793
foreach ($controls as $value) {
88-
$url = empty($value['url']) ? '' : $value['url'];
89-
$icon = empty($value['icon']) ? '' : $value['icon'];
90-
$name = empty($value['name']) ? '' : $value['name'];
91-
$attr = empty($value['attr']) ? [] : $value['attr'];
92-
$class = empty($value['pixattr']['class']) ? '' : $value['pixattr']['class'];
93-
$al = new action_menu_link_secondary(
94-
new moodle_url($url),
95-
new pix_icon($icon, '', null, ['class' => "smallicon " . $class]),
96-
$name,
97-
$attr
98-
);
99-
$menu->add($al);
94+
if ($sectiondelegate) {
95+
if ($value instanceof action_menu_link) {
96+
$value->add_class('cm-edit-action');
97+
}
98+
$menu->add($value);
99+
} else {
100+
$url = empty($value['url']) ? '' : $value['url'];
101+
$icon = empty($value['icon']) ? '' : $value['icon'];
102+
$name = empty($value['name']) ? '' : $value['name'];
103+
$attr = empty($value['attr']) ? [] : $value['attr'];
104+
$class = empty($value['pixattr']['class']) ? '' : $value['pixattr']['class'];
105+
$al = new action_menu_link_secondary(
106+
new moodle_url($url),
107+
new pix_icon($icon, '', null, ['class' => "smallicon " . $class]),
108+
$name,
109+
$attr
110+
);
111+
$menu->add($al);
112+
}
100113
}
101114

102115
$data = (object)[

course/format/classes/sectiondelegate.php

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
namespace core_courseformat;
1818

19+
use core_courseformat\output\local\content\section\controlmenu;
20+
use core_courseformat\base as course_format;
1921
use section_info;
2022

2123
/**
@@ -77,4 +79,17 @@ protected static function get_delegate_class_name(string $pluginname): ?string {
7779
public static function has_delegate_class(string $pluginname): bool {
7880
return self::get_delegate_class_name($pluginname) !== null;
7981
}
82+
83+
/**
84+
* Allow delegate plugin to modify the available section actions.
85+
*
86+
* @param controlmenu $controlmenu The control menu instance.
87+
* @return array The new list of edit control items.
88+
*/
89+
public function get_section_options(
90+
course_format $format,
91+
controlmenu $controlmenu,
92+
): array {
93+
return $controlmenu->section_control_items();
94+
}
8095
}

course/section.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,19 @@
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+
$PAGE->add_header_action($controlmenuhtml);
153+
$sectionheading = $OUTPUT->render($format->inplace_editable_render_section_name($sectioninfo, false));
154+
$PAGE->set_heading($sectionheading, false, false);
155+
$headingset = true;
156+
}
157+
}
158+
if (!$headingset) {
154159
$PAGE->set_heading($sectiontitle);
155160
}
156161

0 commit comments

Comments
 (0)