找出要使用的钩子

问题描述 投票:0回答:1

我正在开发一个模块,它的功能类似于nodereferences_url。

要实现哪个 Drupal 钩子才能将链接中的链接放置到节点内容区域中,如附图中突出显示的那样?

enter image description here

drupal-6 drupal-modules drupal-hooks
1个回答
0
投票

就是hook_link(),其描述为:

这个钩子使模块能够添加到 Drupal 许多部分的链接。例如,可以在节点或导航块中添加链接。

返回的数组应该是链接条目的键控数组。每个链接可以采用两种格式之一。

该钩子的实现示例是 node_link(),其中包含以下代码:

function node_link($type, $node = NULL, $teaser = FALSE) {
  $links = array();

  if ($type == 'node') {
    if ($teaser == 1 && $node->teaser && !empty($node->readmore)) {
      $links['node_read_more'] = array(
        'title' => t('Read more'), 
        'href' => "node/$node->nid",
        // The title attribute gets escaped when the links are processed, so
        // there is no need to escape here. 
        'attributes' => array('title' => t('Read the rest of !title.', array('!title' => $node->title))),
      );
    }
  }

  return $links;
}

这是当节点内容多于预告片中已显示的内容时,在节点的预告片中添加“阅读更多”链接的代码。

注意,钩子是为节点和注释调用的。如文档中所述,

$type
参数可以具有以下值:

  • “评论”:要放置在正在查看的评论下方的链接。
  • “节点”:要放置在正在查看的节点下方的链接。
© www.soinside.com 2019 - 2024. All rights reserved.