From ed765cfad15c072f2810fcbf49e12ed8a7f4aac8 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Mon, 31 Jul 2017 19:40:54 +0800 Subject: [PATCH] MDL-59612 course: Use action_link template for activity navigation Part of MDL-59313. --- course/classes/output/activity_navigation.php | 33 +++++++++++------ course/templates/activity_navigation.mustache | 36 +++++++++++++++---- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/course/classes/output/activity_navigation.php b/course/classes/output/activity_navigation.php index 51c44632072..9e47b35c384 100644 --- a/course/classes/output/activity_navigation.php +++ b/course/classes/output/activity_navigation.php @@ -38,14 +38,14 @@ use templatable; class activity_navigation implements renderable, templatable { /** - * @var string The html for the prev link + * @var \action_link The action link object for the prev link. */ - public $prevlink = ''; + public $prevlink = null; /** - * @var string The html for the next link + * @var \action_link The action link object for the next link. */ - public $nextlink = ''; + public $nextlink = null; /** * Constructor. @@ -64,8 +64,12 @@ class activity_navigation implements renderable, templatable { $linkname .= ' ' . get_string('hiddenwithbrackets'); } - $link = new \action_link($linkurl, $OUTPUT->larrow() . ' ' . $linkname); - $this->prevlink = $OUTPUT->render($link); + $attributes = [ + 'classes' => 'btn btn-link', + 'id' => 'prev-activity-link', + 'title' => $linkname, + ]; + $this->prevlink = new \action_link($linkurl, $OUTPUT->larrow() . ' ' . $linkname, null, $attributes); } // Check if there is a next module to display. @@ -76,8 +80,12 @@ class activity_navigation implements renderable, templatable { $linkname .= ' ' . get_string('hiddenwithbrackets'); } - $link = new \action_link($linkurl, $linkname . ' ' . $OUTPUT->rarrow()); - $this->nextlink = $OUTPUT->render($link); + $attributes = [ + 'classes' => 'btn btn-link', + 'id' => 'next-activity-link', + 'title' => $linkname, + ]; + $this->nextlink = new \action_link($linkurl, $linkname . ' ' . $OUTPUT->rarrow(), null, $attributes); } } @@ -89,8 +97,13 @@ class activity_navigation implements renderable, templatable { */ public function export_for_template(\renderer_base $output) { $data = new \stdClass(); - $data->prevlink = $this->prevlink; - $data->nextlink = $this->nextlink; + if ($this->prevlink) { + $data->prevlink = $this->prevlink->export_for_template($output); + } + + if ($this->nextlink) { + $data->nextlink = $this->nextlink->export_for_template($output); + } return $data; } diff --git a/course/templates/activity_navigation.mustache b/course/templates/activity_navigation.mustache index 626cf336555..fb9c390328f 100644 --- a/course/templates/activity_navigation.mustache +++ b/course/templates/activity_navigation.mustache @@ -20,25 +20,49 @@ Displays the activity navigation Context variables required for this template: - * prevlink - The link to the previous module the user can see - * nextlink - The link to the next module the user can see + * 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. Example context (json): { - "prevlink": "The origins of Moodle", - "nextlink": "Moodlers - are they contagious?" + "prevlink": { + "disabled": false, + "url": "#", + "id": "test-id-1", + "classes": "btn btn-link", + "attributes": [ + { + "name": "title", + "value": "Activity A" + } + ], + "text": "◄ Activity A" + }, + "nextlink": { + "disabled": false, + "url": "#", + "id": "test-id-2", + "classes": "btn btn-link", + "attributes": [ + { + "name": "title", + "value": "Activity C" + } + ], + "text": "Activity C ►" + } } }}
{{< core/columns-1to1to1}} {{$column1}}
- {{{prevlink}}} + {{#prevlink}}{{> core/action_link }}{{/prevlink}}
{{/column1}} {{$column3}}
- {{{nextlink}}} + {{#nextlink}}{{> core/action_link }}{{/nextlink}}
{{/column3}} {{/ core/columns-1to1to1}}