1

我的问题是:“将字段数据添加到引用节点而不替换现有数据”。

例如,我有一个项目节点,其中团队成员引用了该项目。每个团队成员在其节点上都有一个位置,即“英国”、“美国”、“澳大利亚”。

在项目节点上,我有那些完全相同的字段。我需要创建一个规则,以便在创建“团队成员”节点时,将其位置添加到项目节点而不替换现有内容。

因此,例如,具有来自英国的团队成员的项目节点也将在其位置字段中具有“英国”。添加来自“美国”的团队成员时,项目的位置字段将包含“英国”和“美国”。当添加一个同时位于加拿大和法国的团队成员时,项目的位置将变为英国、美国、加拿大和法国。

谢谢!

做类似的事情:

return array(
  0 => array('value' => 'United Kingdom')
);

就是行不通!它将替换现有值。我如何使它添加到现有值。谢谢!

4

3 回答 3

1

在节点上实际具有引用或仅显示位置是否重要。

如果您只是担心显示位置,那么我认为您可以通过 view 轻松完成此操作。

我相信有一个节点引用反向选项,但这只会显示团队成员而不是位置。

如果在项目节点中实际拥有位置信息很重要,那么您将不得不使用 hook_nodeapi op = save代码类似于Matts 的答案

于 2010-02-17T09:50:19.157 回答
0

这样的事情会起作用吗?基本上我们捕获当前节点 cck 位置字段(更改下面的字段名称以适应),加载参考节点,并将位置数据添加到它,并将其保存起来。我没有添加代码来检查该位置是否已经存在,但这是另一天的事情。- 希望能帮助到你。

#some debug data below
#krumo ($node);
#print "<pre>". print_r($node,true) . "</pre>";

#$node is our current data set

# save the current $node nid into a variable
$nid = $node->nid; 
#get the reference nid 
$refnid = $node->field_refnid[0][nid];
#get the location
$currentlocation = $node->field_team_location[0][value];

# nowload the reference node
$refnode = node_load ($refnid);
# some debug data below
#krumo ($refnode);
#print "<pre>". print_r($refnode,true) . "</pre>";

$newlocation = array ("value"=>$currentlocation);
$refnode->field_loacations[] = $newlocation;
#now save the reference node
node_save ($refnode);

#drupal_goto ("node/$nid");
于 2010-02-17T09:15:33.613 回答
-1

你有没有尝试过:

return array(
  array('value' => 'United Kingdom'),
  array('value' => 'United States'),
);
于 2010-02-17T04:04:59.810 回答