function book_node_links_alter in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/book/book.module \book_node_links_alter()
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 &$node_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) {
$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')) {
$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($links)) {
$node_links['book'] = array(
'#theme' => 'links__node__book',
'#links' => $links,
'#attributes' => array(
'class' => array(
'links',
'inline',
),
),
);
}
}
}