You are here

function book_node_view in Drupal 8

Same name and namespace in other branches
  1. 7 modules/book/book.module \book_node_view()
  2. 9 core/modules/book/book.module \book_node_view()
  3. 10 core/modules/book/book.module \book_node_view()

Implements hook_ENTITY_TYPE_view() for node entities.

File

core/modules/book/book.module, line 229
Allows users to create and organize related content in an outline.

Code

function book_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) {
  if ($view_mode == 'full') {
    if (!empty($node->book['bid']) && empty($node->in_preview)) {
      $book_node = Node::load($node->book['bid']);
      if (!$book_node
        ->access()) {
        return;
      }
      $build['book_navigation'] = [
        '#theme' => 'book_navigation',
        '#book_link' => $node->book,
        '#weight' => 100,
        // The book navigation is a listing of Node entities, so associate its
        // list cache tag for correct invalidation.
        '#cache' => [
          'tags' => $node
            ->getEntityType()
            ->getListCacheTags(),
        ],
      ];
    }
  }
}