1 book.module book_node_view_link(Node $node, $view_mode)

Adds relevant book links to the node's links.

Parameters

Node $node: The book page node to add links to.

$view_mode: The display mode of the node.

File

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

Code

function book_node_view_link(Node $node, $view_mode) {
  $links = array();
  $config = config('book.settings');
  $link_options = $config->get('book_links');

  if (isset($node->book['depth'])) {
    if ($view_mode == 'full' && node_is_page($node)) {
      $child_type = $config->get('book_child_type');
      $admin_access = user_access('add content to books') || user_access('administer book outlines');
      $link_options = $config->get('book_links');
      $create_access = node_access('create', $child_type);
      $depth_allowed = $node->book['depth'] < MENU_MAX_DEPTH;
      $show_add_child_link = in_array('book_add_child', $link_options, TRUE);
      $show_reorder_link = in_array('book_reorder', $link_options, TRUE);
      if ($admin_access && $create_access && $node->status == 1 && $depth_allowed && $show_add_child_link) {
        $links['book_add_child'] = array(
          'title' => t('Add child page'),
          'href' => 'node/add/' . str_replace('_', '-', $child_type),
          'query' => array('parent' => $node->book['mlid']),
        );
      }
      if (user_access('administer book outlines') && $show_reorder_link) {
        $links['book_reorder'] = array(
          'title' => t('Reorder book'),
          'href' => 'admin/content/book/' . $node->book['bid'],
        );
      }
    }
  }

  if (!empty($links)) {
    $node->content['links']['book'] = array(
      '#theme' => 'links__node__book',
      '#links' => $links,
      '#attributes' => array('class' => array('links', 'inline')),
    );
  }
}