You are here

public function Course::getNavigation in Course 8.3

Same name and namespace in other branches
  1. 8.2 src/Entity/Course.php \Drupal\course\Entity\Course::getNavigation()
  2. 3.x src/Entity/Course.php \Drupal\course\Entity\Course::getNavigation()

Generate navigation links.

File

src/Entity/Course.php, line 180

Class

Course
Defines the Course entity class.

Namespace

Drupal\course\Entity

Code

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'] = \Drupal\Core\Link::fromTextAndUrl(t('Previous'), $prev
      ->getUrl());
  }
  $links['back'] = \Drupal\Core\Link::createFromRoute(t('Back to course'), 'entity.course.canonical', [
    'course' => $this
      ->id(),
  ]);
  if ($next && $next
    ->access('take')) {
    $links['next'] = \Drupal\Core\Link::fromTextAndUrl(t('Next'), $next
      ->getUrl());
  }
  elseif (!$next && $this
    ->getTracker($account)
    ->isComplete()) {
    $links['next'] = \Drupal\Core\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;
}