public function CourseObjectBook::overrideNavigation in Course 3.x
Same name and namespace in other branches
- 8.3 modules/course_book/src/Plugin/course/CourseObject/CourseObjectBook.php \Drupal\course_book\Plugin\course\CourseObject\CourseObjectBook::overrideNavigation()
- 8.2 modules/course_book/src/Plugin/course/CourseObject/CourseObjectBook.php \Drupal\course_book\Plugin\course\CourseObject\CourseObjectBook::overrideNavigation()
Overrides navigation links.
Overrides CourseObject::overrideNavigation
File
- modules/
course_book/ src/ Plugin/ course/ CourseObject/ CourseObjectBook.php, line 122
Class
- CourseObjectBook
- Plugin annotation @CourseObject( id = "book", label = "Book", handlers = { "fulfillment" = "\Drupal\course_book\Plugin\course\CourseObject\CourseObjectBookFulfillment" } )
Namespace
Drupal\course_book\Plugin\course\CourseObjectCode
public function overrideNavigation() {
$links = parent::overrideNavigation();
$route_match = Drupal::routeMatch();
if ($route_match
->getRouteName() == 'entity.node.canonical') {
$node = $route_match
->getParameter('node');
/* @var $book_outline Drupal\book\BookOutline */
$book_outline = \Drupal::service('book.outline');
if (isset($node->book)) {
$book_link = $node->book;
if ($prev = $book_outline
->prevLink($book_link)) {
$links['prev'] = Link::createFromRoute(t('Previous'), 'entity.node.canonical', [
'node' => $prev['nid'],
]);
}
if ($next = $book_outline
->nextLink($book_link)) {
$links['next'] = Link::createFromRoute(t('Next'), 'entity.node.canonical', [
'node' => $next['nid'],
]);
}
}
return $links;
}
}