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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 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' )), ); } } } |
Please login to continue.