Hi All,
I am getting mad finding the right way to achieve the following simple thing.
I have two node types: A and B
A has node reference to B (can have many values, so a node a can refer many nodes b)
When showing a node of type A, i have created a VBO to let user selec the node of Type B to be referred by A.
I am trying to create a component rule to do this but without success, cannot find the way to create such rule.
-Is it possible to achieve this though the component rule? can the action add a reference in a node reference field? How?
-Alternatively, i may create a custom php code action to be triggered by VBO, but i am really beginner, can't understand how to write this custom php action. I have been able to understand that the VBO pass the $entity (node B), then i need to fill in the current viewed node (a)as node B and the current viewed node.
Moreover, i would like the VBO on B not to list the B nodes that are already referenced by A (current node).
Thank you all in advance for the support
Comments
I have been finally able to
I have been finally able to achieve it. I create a custom php code rule that load the current node and call a my module function.
This rule is triggered by the vbo:
$nodeA =node_load(arg(1))
function MySite_util_ANodeReferenceToB($entityB, &$nodeA)
{
$referencetoadd = array('nid' => $entityB->nid, 'value' => $entityB->title);
$index =0;
foreach ($nodeA->field_nodeReferenceToB['und'] as $link) {
if($link['nid'] == $referencetoadd['nid'])
return;
$index = $index+1;
}
$nodeA->field_nodeReferenceToB['und'][$index] = $referencetoadd;
node_save($nodeA);
}
Now i have another problem. I want to remove from the vbo view the nodes B that are already referenced by B.
How can i create a View that list all nodes of type B that are NOT referenced by A?
this maybe the solution for my project
thanks for sharing the code, if you please provide step by step instruction in implementing this rule. I might help creating the views for you
thanks
Document Tracking
I have a project relating to dispatching of document using a bar code. Do anyone have idea how can I start with the development of the said project
Hijacking this post is not a
Hijacking this post is not a good way to get help. I have already responded to your post on this at http://drupal.org/node/1833098
Jon Heaton