It would be nice to have the option to redirect the user to the node-edit form for the new node once the form is submitted, so that the user can fill out the rest of the fields. The attached patch provides the option. To use, go to the field configuration and you will see a checkbox for the purpose.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Fanaile’s picture

So far so good;

I had to apply the patch manually, since I use Windows and I couldn't get any of the windows programs that were posted (in multiple places) to work for me.

But so far I have had no problem with this. No errors reported, and the redirect worked great.

I have not yet tried using this when adding more than one node reference that need to be created. But I have tried it with different content types and each one worked well. I will work on testing it out with multiple creations later on today.

Fanaile’s picture

There is probably no really easy way around this... Here is what I did.

I have this currently installed on a new site (http://statusje.ipower.com) with two types of node reference create fields, one for job openings and another for events. I created a test listing in which I added one node reference of each type. I received the following notice-message at the top:

* Programmer Needed was created. Please enter the rest of the information.
* job fair was created. Please enter the rest of the information.
* Non-profit Organization or Club listing test has been created.

And I was redirected to fill in the event type (job fair) opening. Upon saving the event type, I was directed to the event view. So to fill in the information for the job opening, I would still need to look for that post before I could fill in the necessary information.

I was thinking it might be possible to work around this by using content complete; but it seems as though content complete only gives you the choice of showing the current node or the first node of that type. I tried with both options and neither one left an easy work around. But maybe there is a way to integrate it or customize it a bit further so that it will leave a message with a link for all nodes created this way that members haven't yet completed? Or, for example, when I complete the one that was referenced, leave a message that says something along the lines of "you still need to complete this one" with a link?

sbauch’s picture

Where do I implement this patch? Do i paste the code into an existing file or does it stand alone?

edit: yeah really noob question, sorry. patch works great for me, but I would love to auto populate the reference field. So when the referenced node doesn't exist, and the user is brought to the next page to complete the node, they don't have to retype the entry.

akamaus’s picture

Version: 6.x-1.0 » 7.x-1.0
FileSize
2.29 KB

I ported the original poster's patch to D7. The original didn't work right in case when several nodes were created in a row. The user got redirected to the first one only. Mine version solves this by storing all pending redirections in a session variable.

froboy’s picture

I liked akamaus's patch, but in my case I'd rather have the user redirected to the view of the node that their reference originated from rather than the view of the new referenced node. I worked this up and added it on top of the patch from #4. This adds another checkbox in the configuration page to give the option of redirecting back to the origin. I'm not sure if my code does this in the most efficient way, but I tried to work into akamaus's code without modifying the method too much. Let me know what you all think.

EDIT: Do not use this patch, use the one below.

froboy’s picture

Oops, above patch still had debugging code in it. Please use this one.

SocialNicheGuru’s picture

what if there are multiple nodes created?

akamaus’s picture

> what if there are multiple nodes created?
This was the use case for my patch. User would be redirected to all the created nodes one after another. He presses 'save' and gets next one.

BrockBoland’s picture

Updated froboy's patch a bit here. noderefcreate_node_submit() throws the occasional notice because $_SESSION['noderefcreate_redirects'] isn't set ("Notice: Undefined index: noderefcreate_redirects in noderefcreate_node_submit()"). This sets that var to an array.

I also fixed up some coding standard issues, mostly where curly braces were missing for single-line conditionals. I'm including the interdiff so you can see what I added to the patch in #6.

neoander’s picture

Thanks for the patch you guys it worked like magic. I was actually trying to get this to work through rules it almost did but the only problem was i couldn't identify the node that was referenced had already existed on the database or not. So i was looking for this and it was amazing and even more it redirects to more than one node.

Here is my problem i had user account creation page where the user would enter their company name, which then it should redirect to the referenced content type "Companies". It creates the company it just doesn't forward it as it would, like from node to node reference. I would really appreciate if it could also refer from user to node. Oh and one more thing when adding multiple node references if the first node referred already exist in the database it shows some weird page. This has helped me a lot thanks.

JGonzalez’s picture

Issue summary: View changes

This patch doesn't seem to redirect to originally created node after the referenced node is saved. It redirects to /node/ after the newly created node is saved. Did something change?

It looks as if

 $origin = 'node/' . $form_state['values']['nid'];

Returns null instead of returning the just created node.