In my use case, I needed to adjust the language of the node being created. To solve this, I added a hook_noderefcreate_alter to allow other modules to manipulate the node being created. Patch attached.

Comments

jackbravo’s picture

Status: Active » Needs review

just marking as needs review. I don't have time right now, but maybe later or someone else beats me to it.

I'd say this looks good.

tinker’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new647 bytes

I think this is an excellent mod and have successfully tested the patch. In my use case I have node type A that is used as reference data for node type B. The end user can select an existing node reference A, if it exists, that is then used to auto-populate the node B form with reference data. If the reference node does not exist a new reference node A is created using data from the form values provided by the user in node B.

e.g. User is creating a for sale ad for a car and can select a node reference to the car model. If it exists then the specifications for the car model are copied to the ad form. If it does not exist then the user data is used to create a new node reference car model node.

I have made one tiny change by adding the $form_state to the drupal_alter function so that I can grab form values for use in creating the $newnode.

Scratch that; later discovered that form_state values are already passed in $element['#post'] so it was not needed. Please disregard the attached patch and use the original by @infojunkie which I have now thoroughly tested.

Michsk’s picture

I would like to see this option aswell. Would it be posible to attach a fivestar rating then with this patch?

mlsamuelson’s picture

Just a quick note: The changes in patch #2 work with the 7.x-1.0 version of Node Reference Create without requiring any adjustments for API changes in Drupal 7. The patch will probably need to be re-rolled, though, when ready. I just manually made the changes.

cthiebault’s picture

Version: 6.x-1.0 » 7.x-1.0-beta3
StatusFileSize
new1.26 KB
new777 bytes

Here is the same patch for the latest dev version (4268ba7 on 7.x-1.x).
You just need to implements hook_noderefcreate_alter:

function MY_MODULE_noderefcreate_alter(&$newnode, $element, $form_state) {
}

I've also created a new patch that is a merge of this patch with http://drupal.org/files/noderefcreate-workflow-options-892052-4.patch from Ignoring workflow and comment settings.