drupal规则将字段数据添加到引用的节点而不替换现有数据

发布于 2024-08-21 19:21:03 字数 457 浏览 8 评论 0 原文

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

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

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

例如,具有来自英国的团队成员的项目节点的位置字段上也会有“英国”。添加来自“美国”的团队成员后,项目的位置字段将包含“英国”和“美国”。添加位于加拿大和法国的团队成员后,项目的位置将变为英国、美国、加拿大和法国。

谢谢!

做类似的事情:

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

根本行不通!它将取代现有的价值观。我该如何制作它才能增加现有的价值。谢谢!

My question is about: "adding field data to referenced node without replacing existing data".

For example, I have a project node with team members referencing the project. Each team member has on its node a location, ie, 'United Kingdom', 'United States', 'Australia'.

On the project node I have those exact same fields. I need to create a rule so that when a 'team member' node is created, its location is added to the project node without replacing existing content.

So for instance, a project node with a team member from the United Kingdom would also have on its location field, 'United Kingdom'. When a team member from 'United States' is added, the project's location field would have 'United Kingdom' and 'United States'. When a team member who's location is both Canada AND France is added, the project's location becomes United Kingdom, United States, Canada, and France.

Thanks!

Doing something like:

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

Just wouldn't work! It would replace the existing values. How do I make it so that it adds on to the existing values. Thanks!

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

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

发布评论

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

评论(3

眼睛会笑 2024-08-28 19:21:03

节点上的实际引用重要还是仅显示位置重要。

如果您只是担心显示位置,那么我认为您可以使用 轻松完成此操作查看

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

如果在项目节点中实际拥有位置信息很重要,那么您必须 使用 hook_nodeapi op = save ,代码类似于 马茨的回答

Is it important to actually have the reference on the node or just to display the location.

If you are just worried about displaying the location then I think you can do this quite easily with a view.

There is a node reference reverse option I believe, but this would only display the team members and not the location.

If it is important to actually have the location information in the project node, then you will have to use hook_nodeapi op = save with code similar to Matts' answer.

司马昭之心 2024-08-28 19:21:03

这样的事情会起作用吗?基本上,我们捕获当前节点的 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");

Will something like this work? Basically we capture the current nodes cck location field (change the field names below to fit), load the reference node, and add the location data to it, and save it away. I've not added the code to check to see if the location already exists, but that's something for another day. - Hope it helps.

#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");
旧城空念 2024-08-28 19:21:03

你有没有尝试过:

return array(
  array('value' => 'United Kingdom'),
  array('value' => 'United States'),
);

Have you tried:

return array(
  array('value' => 'United Kingdom'),
  array('value' => 'United States'),
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文