找出要使用的钩子

发布于 2025-01-01 05:48:11 字数 165 浏览 4 评论 0原文

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

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

在此处输入图像描述

I am working on a module which does something similar to nodereferences_url.

Which Drupal hook to implement to place a link in link into a node content area like is highlighted in the attached image?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞笑我太脆弱 2025-01-08 05:48:11

它是 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 参数可以具有以下值:

  • “comment”:要放置在正在查看的评论下方的链接。
  • “node”:要放置在正在查看的节点下方的链接。

It is hook_link(), which is described as:

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.

An example of implementation of that hook is node_link(), that contains the following code:

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;
}

That is the code that adds the "Read more" link in the teaser of a node, when the node content is more than the content already shown in the teaser.

To notice that the hook is called for nodes, and comments. As described in the documentation, the $type parameter can have the following values:

  • "comment": Links to be placed below a comment being viewed.
  • "node": Links to be placed below a node being viewed.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文