diff --git a/course/classes/output/activity_navigation.php b/course/classes/output/activity_navigation.php index 9e47b35c384..006e0277fe4 100644 --- a/course/classes/output/activity_navigation.php +++ b/course/classes/output/activity_navigation.php @@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die(); use renderable; use templatable; +use url_select; /** * The class activity navigation renderable. @@ -47,13 +48,19 @@ class activity_navigation implements renderable, templatable { */ public $nextlink = null; + /** + * @var url_select The url select object for the activity selector menu. + */ + public $activitylist = null; + /** * Constructor. * * @param \cm_info|null $prevmod The previous module to display, null if none. * @param \cm_info|null $nextmod The previous module to display, null if none. + * @param array $activitylist The list of activity URLs (as key) and names (as value) for the activity dropdown menu. */ - public function __construct($prevmod, $nextmod) { + public function __construct($prevmod, $nextmod, $activitylist = array()) { global $OUTPUT; // Check if there is a previous module to display. @@ -87,6 +94,14 @@ class activity_navigation implements renderable, templatable { ]; $this->nextlink = new \action_link($linkurl, $linkname . ' ' . $OUTPUT->rarrow(), null, $attributes); } + + // Render the activity list dropdown menu if available. + if (!empty($activitylist)) { + $select = new url_select($activitylist, '', array('' => get_string('jumpto'))); + $select->set_label(get_string('jumpto'), array('class' => 'sr-only')); + $select->attributes = array('id' => 'jump-to-activity'); + $this->activitylist = $select; + } } /** @@ -105,6 +120,10 @@ class activity_navigation implements renderable, templatable { $data->nextlink = $this->nextlink->export_for_template($output); } + if ($this->activitylist) { + $data->activitylist = $this->activitylist->export_for_template($output); + } + return $data; } } diff --git a/course/templates/activity_navigation.mustache b/course/templates/activity_navigation.mustache index fb9c390328f..e6439d33f67 100644 --- a/course/templates/activity_navigation.mustache +++ b/course/templates/activity_navigation.mustache @@ -22,6 +22,7 @@ Context variables required for this template: * prevlink Object - The action link data for the previous activity link. Corresponds with the core/action_link context. * nextlink Object - The action link data for the next activity link. Corresponds with the core/action_link context. + * activitylist Object - The data for the activity selector menu. Corresponds with the core/url_select context. Example context (json): { @@ -50,16 +51,31 @@ } ], "text": "Activity C ►" + }, + "activitylist": { + "id": "url_select_test", + "action": "#", + "options": [ + {"name": "Jump to...", "value": "#0"}, + {"name": "Activity A", "value": "#1"}, + {"name": "Activity B", "value": "#2"}, + {"name": "Activity C", "value": "#3"} + ] } } }} -
+
{{< core/columns-1to1to1}} {{$column1}}
{{#prevlink}}{{> core/action_link }}{{/prevlink}}
{{/column1}} + {{$column2}} +
+ {{#activitylist}}{{> core/url_select }}{{/activitylist}} +
+ {{/column2}} {{$column3}}
{{#nextlink}}{{> core/action_link }}{{/nextlink}} diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 9c9c3169bff..83263778c6a 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -837,12 +837,24 @@ class core_renderer extends renderer_base { // Put the modules into an array in order by the position they are shown in the course. $mods = []; + $activitylist = []; foreach ($modules as $module) { // Only add activities the user can access, aren't in stealth mode and have a url (eg. mod_label does not). if (!$module->uservisible || $module->is_stealth() || empty($module->url)) { continue; } $mods[$module->id] = $module; + + // Module name. + $modname = $module->name; + // Display the hidden text if necessary. + if (!$module->visible) { + $modname .= ' ' . get_string('hiddenwithbrackets'); + } + // Module URL. + $linkurl = new moodle_url($module->url, array('forceview' => 1)); + // Add module URL (as key) and name (as value) to the activity list array. + $activitylist[$linkurl->out(false)] = $modname; } $nummods = count($mods); @@ -871,7 +883,7 @@ class core_renderer extends renderer_base { $nextmod = $mods[$modids[$position + 1]]; } - $activitynav = new \core_course\output\activity_navigation($prevmod, $nextmod); + $activitynav = new \core_course\output\activity_navigation($prevmod, $nextmod, $activitylist); $renderer = $this->page->get_renderer('core', 'course'); return $renderer->render($activitynav); }