How remove node ID [nid:n] in NodeReference fields

给你一囗甜甜゛ 提交于 2019-12-08 01:56:15

问题


This is the same question of this link:

Removing [nid:n] in nodereference autocomplete

According with the first answer (Grayside) I've created my own module and activated. Then I create a new content, I look sth up in the nodereference field and finally select it -> it works (Doesn't appear the [nid:n]).

But, when I view/preview or save or edit the content, the [nid:n] appears again.

Anybody can help me?


回答1:


When viewing the node, it is the theming function for the field that determines what is displayed, so you need to overwrite it, if you want to change the output.

The value when you edit the node, is determined by the #default_value property, so you need to change in your hook_form_alter()




回答2:


Thanks for the answer.

I've found the solution. (At least in my case)

I change the code of this file:

drupal\modules\cck\cck\modules\nodereference.module

function nodereference_autocomplete_value($element, $edit = FALSE)
{
  ...
  // $value .= ' [nid:'. $nid .']';    --> Comment this line
  return array($field_key => $value);
}

It works very well! Doesn't appear in any case: Not in selected from the list, nor when save, edit, etc.

Regards!



来源:https://stackoverflow.com/questions/2743924/how-remove-node-id-nidn-in-nodereference-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!