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"} + ] } } }} -