hook_link($type, $node = NULL, $teaser = FALSE)
docs-5/hooks/core.php, line 594
Define internal Drupal links.
This hook enables modules to add links to many parts of Drupal. Links may be added in nodes or in the navigation block, for example.
The returned array should be a keyed array of link entries. Each link can be in one of two formats.
The first format will use the l() function to render the link:
$type An identifier declaring what kind of link is being requested. Possible values:
$teaser In case of node link: a 0/1 flag depending on whether the node is displayed with its teaser or its full form (on a node/nid page)
An array of the requested links.
| Name | Description |
|---|---|
| Hooks | Allow modules to interact with the Drupal core. |
<?php
function hook_link($type, $node = NULL, $teaser = FALSE) {
$links = array();
if ($type == 'node' && isset($node->parent)) {
if (!$teaser) {
if (book_access('create', $node)) {
$links['book_add_child'] = array(
'title' => t('add child page'),
'href' => "node/add/book/parent/$node->nid",
);
}
if (user_access('see printer-friendly version')) {
$links['book_printer'] = array(
'title' => t('printer-friendly version'),
'href' => 'book/export/html/'. $node->nid,
'attributes' => array('title' => t('Show a printer-friendly version of this book page and its sub-pages.'))
);
}
}
}
$links['sample_link'] = array(
'title' => t('go somewhere'),
'href' => 'node/add',
'query' => 'foo=bar',
'fragment' => 'anchorname',
'attributes' => array('title' => t('go to another page')),
);
// Example of a link that's not an anchor
if ($type == 'video') {
if (variable_get('video_playcounter', 1) && user_access('view play counter')) {
$links['play_counter'] = array(
'title' => format_plural($node->play_counter, '1 play', '@count plays'),
);
}
}
return $links;
}
?>