hook_link
developer/hooks/core.php, строка 909
- Версии
- 5
hook_link($type,
$node= NULL, $teaser = FALSE)- 6
hook_link($type, $object, $teaser = FALSE)
Определяет внутренние ссылки Drupal.
Этот хук позволяет модулям добавлять ссылки ко многим частям Друпал. Ссылки могут быть добавлены в нодах или в блоке навигации, например.
Возвращаемый массив должен быть массивом ссылок с ключами. Каждая ссылка может быть в одном из двух форматов.
Первый формат использует функцию l()
для формирования ссылки:
- attributes: Не обязательно. Смотри
l()
для использования. - fragment: Не обязательно. Смотри
l()
для использования. - href: Обязательно. URL ссылки.
- html: Не обязательно. Смотри
l()
для использования. - query: Не обязательно. Смотри
l()
для использования. - title: Обязательно. Имя ссылки.
- title: Required. The text or HTML code to display.
- attributes: Optional. An associative array of HTML attributes to apply to the span tag.
- html: Optional. If not set to true,
check_plain()
will be run on the title before it is displayed.
Параметры
$type
Тип запрашиваемой ссылки.
Возможные значения:
- Комментарий: Links to be placed below a comment being viewed.
- Нода: Links to be placed below a node being viewed.
$object
A node object or a comment object according to the $type
.
$teaser
In case of node link: a 0/1 flag depending on whether the node is
displayed with its teaser or its full form.
Возвращаемое значение
Массив запрошенных ссылок.
Связанные темы
Код
<?php
function hook_link($type, $object, $teaser = FALSE) {
$links = array();
if ($type == 'node' && isset($object->parent)) {
if (!$teaser) {
if (book_access('create', $object)) {
$links['book_add_child'] = array(
'title' => t('add child page'),
'href' => "node/add/book/parent/$object->nid",
);
}
if (user_access('see printer-friendly version')) {
$links['book_printer'] = array(
'title' => t('printer-friendly version'),
'href' => 'book/export/html/'. $object->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($object->play_counter, '1 play', '@count plays'),
);
}
}
return $links;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии