Posted by Fixdit on September 3, 2008 at 10:25am
Can node relativity be utilised on nodes created via node.save in Flash? I have been trying to look for an easy solution to work this out but have been a bit stumped.
I believe, looking at the args when you add a child node to a parent ("/node/add/CONTENTTYPE/parent/PARENTNID") you'd need to have the url available?! Is there anything I can do here? Would I need to write a custom service in PHP that utilise node relativity functionality and tie it in with the node.save service via Flash?
Looking forward to getting some help :)

Comments
Issues list
Ashley,
i dont know if this space was used before as supporting, but it will be much better if you use the Services issues list. The developers tracks that list.
Well, about your problem... i dont know much what is it. Are you talking about Node Relativity module? If so, you need to use Devel module and look all internal content of a node. Then, from there, see how it determines what node is parent from what node and replicate it when trying to save the node on node.save. Confusing, but not difficult.
regards,
massa
Hello again Rob, I thought I
Firstly, BY NO MEANS IS THE CODE BELOW SOMETHING TO BE USED AS IS. :)
I'm indeed talking about the Node Relativity module. I have used the Devel to look at the available variables, but you won't know the child nid before it's created, right? Anyhoo have a look at my theoretical PHP that sketches out what I might want to do. The important Node Relativity part is commented on at the bottom of the code...
/**
* Implementation of hook_service()
*/
function node_service_service() {
return array(
// node.save
array(
'#method' => 'node.save',
'#callback' => 'node_service_save',
'#args' => array(
array(
'#name' => 'node',
'#type' => 'struct',
'#description' => t('A node object. Upon creation, node object must include "type". Upon update, node object must include "nid" and "changed".'))),
'#return' => 'struct',
'#help' => t('Save a node object into the database.')),
function node_service_save($edit) {
// validate node
node_validate($edit);
if ($errors = form_get_errors()) {
return services_error(implode("\n", $errors));
}
$node = node_submit($edit);
node_save($node);
watchdog('content', t('@type: updated %title.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
//This takes the newly created nid for the $child_nid I think??? The Flash is contained on the actual parent node's page, so $parent_nid is in the curent url (arg(1)).
$child_nid = $node->nid;
$parent_nid = arg(1);
db_query('INSERT INTO {relativity} (nid, parent_nid) VALUES (%d, %d)', $child_nid, $parent_nid);
return $node;
}