when I create a node and in-page define a new referenced node with addnode, the owner of the first node is my username but Anonymous for the node created with addnode.

Comments

Lionfish’s picture

Status: Active » Fixed

Well spotted!

I've got a fix that should do the job, but I'm sure there's a better way of doing this (I might need to discuss it with fago as it relates to the subform_element module). I've loaded the node and changed its id, before saving it again:
$new_node = node_load($newnid);
$new_node->uid = $uid;
node_save($new_node);
in addnode_addnids_submit function.

These changes will be in the next release (v1.3).

Thanks for reporting the bug kvantomme!

Mike.

Anonymous’s picture

Status: Fixed » Closed (fixed)
edex13’s picture

since version 5.x-1.3 still not available, can you guide how to fix this problem? where should i put those code in addnode_addnids_submit function?

function addnode_addnids_submit($form_id, &$form_values)
{
   //copied from subform_element_submit, allows us to get hold of the redirects and get the nids from them
  global $subforms;
  if (isset($subforms)) {
    foreach ($subforms as $key => $subform) {
      if (!isset($subform['#submitted'])) {
        $subforms[$key]['#submitted'] = TRUE;
        $redirect = subform_element_call('drupal_submit_form', $subform['#post']['form_id'], $subform);
        $fieldname = $subform['#fieldname'];
        $split = explode("/", $redirect);
        $newnid = $split[1];
        //unset the current array, and replace it with a new array.
        //note that as multiselect is currently set, this is an array
        // @todo allow multi/single select!!
        unset($form_values[$fieldname]['nids']);
        $form_values[$fieldname]['nids'] = array ( $newnid => $newnid );
      }
    }
    return $redirect;
  }
}