public function Course::getNavigation in Course 3.x
Same name and namespace in other branches
- 8.3 src/Entity/Course.php \Drupal\course\Entity\Course::getNavigation()
- 8.2 src/Entity/Course.php \Drupal\course\Entity\Course::getNavigation()
Generate navigation links.
File
- src/
Entity/ Course.php, line 204
Class
- Course
- Defines the Course entity class.
Namespace
Drupal\course\EntityCode
public function getNavigation(AccountInterface $account) {
// Initialize the active Course.
$this
->setActive();
$prev = $this
->getPrev();
$next = $this
->getNext();
$links = array();
if ($prev && $prev
->access('take')) {
$links['prev'] = Link::fromTextAndUrl(t('Previous'), $prev
->getUrl());
}
$links['back'] = Link::createFromRoute(t('Back to course'), 'entity.course.canonical', [
'course' => $this
->id(),
]);
if ($next && $next
->access('take')) {
$links['next'] = Link::fromTextAndUrl(t('Next'), $next
->getUrl());
}
elseif (!$next && $this
->getEnrollment($account)
->isComplete()) {
$links['next'] = Link::createFromRoute(t('Next'), 'course.complete', [
'course' => $this
->id(),
]);
}
// Ask course objects if they want to override the navigation.
if ($active = $this
->getActive()) {
foreach ($active
->overrideNavigation() as $key => $link) {
$links[$key] = $link;
}
}
return $links;
}