function book_node_links_alter
Same name in other branches
- 9 core/modules/book/book.module \book_node_links_alter()
- 8.9.x core/modules/book/book.module \book_node_links_alter()
- 10 core/modules/book/book.module \book_node_links_alter()
Implements hook_node_links_alter().
File
-
core/
modules/ book/ book.module, line 92
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::entityTypeManager()->getAccessControlHandler('node');
if (($account->hasPermission('add content to books') || $account->hasPermission('administer book outlines')) && $access_control_handler->createAccess($child_type) && $node->book['depth'] < BookManager::BOOK_MAX_DEPTH) {
$book_links['book_add_child'] = [
'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'] = [
'title' => t('Printer-friendly version'),
'url' => Url::fromRoute('book.export', [
'type' => 'html',
'node' => $node->id(),
]),
'attributes' => [
'title' => t('Show a printer-friendly version of this book page and its sub-pages.'),
],
];
}
}
}
if (!empty($book_links)) {
$links['book'] = [
'#theme' => 'links__node__book',
'#links' => $book_links,
'#attributes' => [
'class' => [
'links',
'inline',
],
],
];
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.