function hook_node_links_alter
Same name in other branches
- 9 core/modules/node/node.api.php \hook_node_links_alter()
- 8.9.x core/modules/node/node.api.php \hook_node_links_alter()
- 10 core/modules/node/node.api.php \hook_node_links_alter()
Alter the links of a node.
Parameters
array &$links: A renderable array representing the node links.
\Drupal\node\NodeInterface $entity: The node being rendered.
array &$context: Various aspects of the context in which the node links are going to be displayed, with the following keys:
- 'view_mode': the view mode in which the node is being viewed
- 'langcode': the language in which the node is being viewed
See also
\Drupal\node\NodeViewBuilder::renderLinks()
\Drupal\node\NodeViewBuilder::buildLinks()
Entity CRUD, editing, and view hooks
Related topics
2 functions implement hook_node_links_alter()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- book_node_links_alter in core/
modules/ book/ book.module - Implements hook_node_links_alter().
- statistics_node_links_alter in core/
modules/ statistics/ statistics.module - Implements hook_node_links_alter().
File
-
core/
modules/ node/ node.api.php, line 416
Code
function hook_node_links_alter(array &$links, NodeInterface $entity, array &$context) {
$links['my_module'] = [
'#theme' => 'links__node__my_module',
'#attributes' => [
'class' => [
'links',
'inline',
],
],
'#links' => [
'node-report' => [
'title' => t('Report'),
'url' => Url::fromRoute('node_test.report', [
'node' => $entity->id(),
], [
'query' => [
'token' => \Drupal::getContainer()->get('csrf_token')
->get("node/{$entity->id()}/report"),
],
]),
],
],
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.