Skip to content

Commit

Permalink
MDL-59612 course: Use action_link template for activity navigation
Browse files Browse the repository at this point in the history
Part of MDL-59313.
  • Loading branch information
junpataleta committed Jul 31, 2017
1 parent 1678181 commit ed765cf
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 16 deletions.
33 changes: 23 additions & 10 deletions course/classes/output/activity_navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
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.
Expand All @@ -64,8 +64,12 @@ public function __construct($prevmod, $nextmod) {
$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.
Expand All @@ -76,8 +80,12 @@ public function __construct($prevmod, $nextmod) {
$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);
}
}

Expand All @@ -89,8 +97,13 @@ public function __construct($prevmod, $nextmod) {
*/
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;
}
Expand Down
36 changes: 30 additions & 6 deletions course/templates/activity_navigation.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<a href='#'>The origins of Moodle</a>",
"nextlink": "<a href='#'>Moodlers - are they contagious?</a>"
"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 ►"
}
}
}}
<div>
{{< core/columns-1to1to1}}
{{$column1}}
<div class="pull-left">
{{{prevlink}}}
{{#prevlink}}{{> core/action_link }}{{/prevlink}}
</div>
{{/column1}}
{{$column3}}
<div class="pull-right">
{{{nextlink}}}
{{#nextlink}}{{> core/action_link }}{{/nextlink}}
</div>
{{/column3}}
{{/ core/columns-1to1to1}}
Expand Down

0 comments on commit ed765cf

Please sign in to comment.