删除节点引用自动完成中的 [nid:n] [英] Removing [nid:n] in nodereference autocomplete

查看:17
本文介绍了删除节点引用自动完成中的 [nid:n]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对 cck 节点引用使用自动完成字段总是将节点 ID 显示为一个隐蔽的括号扩展名:

Using the autocomplete field for a cck nodereference always displays the node id as a cryptic bracketed extension:

Page Title [nid:23]

我知道这可以确保在节点具有相同标题的情况下选择是唯一的,但显然,向用户公开这是一件令人讨厌的事情.

I understand that this ensures that selections are unique in case nodes have the same title, but obviously this is a nasty thing to expose to the user.

有没有人成功删除这些括号或添加不同的唯一标识符?

Has anyone had any success in removing these brackets, or adding a different unique identifier?

推荐答案

最终,你需要改变 nodereference.module 中 nodereference_autocomplete() 的输出.

Ultimately, you need to change the output of nodereference_autocomplete() in nodereference.module.

要正确执行此操作,您需要一个自定义模块来干净地覆盖该函数.

To do this properly, you want a custom module to cleanly override the function.

这个函数被定义为一个菜单回调,因此,

This function is defined as a menu callback, thus,

/**
 * Implementation of hook_menu_alter().
 */
function custom_module_menu_alter(&$items) {
  $items['nodereference/autocomplete']['page callback'] = 'custom_module_new_nodereference_autocomplete';
}

然后,将 nodereference_autocomplete 函数复制到您的自定义模块中,更改其名称以匹配您的回调.然后改变这一行:

Then, copy the nodereference_autocomplete function into your custom module, changing it's name to match your callback. Then change this one line:

$matches[$row['title'] ." [nid:$id]"] = '<div class="reference-autocomplete">'. $row['rendered'] . '</div>';

删除 nid 引用.

$matches[$row['title']] = '<div class="reference-autocomplete">'. $row['rendered'] . '</div>';

我相信此时标识符纯粹是装饰性的,这意味着您也可以随意更改文本.如果它不是纯粹的装饰品,那么我还没有测试过在错误的条件下会发生什么.

I believe the identifier is purely cosmetic at this point, which means you could also change the text however you like. If it is not purely cosmetic, well, I haven't tested to see what will happen in the wrong conditions.

我一直想确定如何做到这一点.谢谢你的问题激励我.

I always meant to identify how to do this. Thank you for motivating me with your question.

这篇关于删除节点引用自动完成中的 [nid:n]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆