MDL-59612 course: Use action_link template for activity navigation
Part of MDL-59313.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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}}
|
||||
|
||||
Reference in New Issue
Block a user