W3cubDocs

/Drupal 8

function hook_node_links_alter

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'),
        '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.
https://api.drupal.org/api/drupal/core!modules!node!node.api.php/function/hook_node_links_alter/8.1.x