function book_node_view

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

Implements hook_ENTITY_TYPE_view() for node entities.

File

core/modules/book/book.module, line 229

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(),
        ],
      ];
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.