/Drupal 8

function hook_node_links_alter

hook_node_links_alter(array &$links, NodeInterface $entity, array &$context)

Alter the links of a node.


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



Entity CRUD, editing, and view hooks

Related topics

Define functions that alter the behavior of Drupal core.


core/modules/node/node.api.php, line 488
Hooks specific to the Node module.


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'),
        'href' => "node/{$entity->id()}/report",
        'query' => array('token' => \Drupal::getContainer()->get('csrf_token')->get("node/{$entity->id()}/report")),

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.