book_node_links_alter

book_node_links_alter(array &$links, NodeInterface $node, array &$context)

Implements hook_node_links_alter().

File

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

Code

function book_node_links_alter(array &$links, NodeInterface $node, array &$context) {
  if ($context['view_mode'] != 'rss') {
    $account = \Drupal::currentUser();

    if (isset($node->book['depth'])) {
      if ($context['view_mode'] == 'full' && node_is_page($node)) {
        $child_type = \Drupal::config('book.settings')->get('child_type');
        $access_control_handler = \Drupal::entityManager()->getAccessControlHandler('node');
        if (($account->hasPermission('add content to books') || $account->hasPermission('administer book outlines')) && $access_control_handler->createAccess($child_type) && $node->isPublished() && $node->book['depth'] < BookManager::BOOK_MAX_DEPTH) {
          $book_links['book_add_child'] = array(
            'title' => t('Add child page'),
            'url' => Url::fromRoute('node.add', ['node_type' => $child_type], ['query' => ['parent' => $node->id()]]),
          );
        }

        if ($account->hasPermission('access printer-friendly version')) {
          $book_links['book_printer'] = array(
            'title' => t('Printer-friendly version'),
            'url' => Url::fromRoute('book.export', [
              'type' => 'html',
              'node' => $node->id(),
            ]),
            'attributes' => array('title' => t('Show a printer-friendly version of this book page and its sub-pages.'))
          );
        }
      }
    }

    if (!empty($book_links)) {
      $links['book'] = array(
        '#theme' => 'links__node__book',
        '#links' => $book_links,
        '#attributes' => array('class' => array('links', 'inline')),
      );
    }
  }
}
doc_Drupal
2016-10-29 08:48:37
Comments
Leave a Comment

Please login to continue.