hook_node_links_alter(array &$links, NodeInterface $entity, array &$context)
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
- Hooks
- Define functions that alter the behavior of Drupal core.
File
- core/modules/node/node.api.php, line 488
- Hooks specific to the Node module.
Code
function hook_node_links_alter(array &$links, NodeInterface $entity, array &$context) { $links['mymodule'] = array( '#theme' => 'links__node__mymodule', '#attributes' => array('class' => array('links', 'inline')), '#links' => array( 'node-report' => array( 'title' => t('Report'), 'url' => Url::fromRoute('node_test.report', ['node' => $entity->id()], ['query' => ['token' => \Drupal::getContainer()->get('csrf_token')->get("node/{$entity->id()}/report")]]), ), ), ); }
Please login to continue.