Add node reference bug when EDITING an EXISTING node
nodecode - July 2, 2009 - 08:34
| Project: | Popups: Add and Reference |
| Version: | 5.x-1.0-beta2 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | needs review |
Jump to:
Description
I am having the same problem seen here which was an issue with version 5x-1.0-beta1.
Here's the problem in detail:
If I have an existing Page node with a node-reference type of Story:
- While EDITING the existing Page node...
- On the Page edit form, I click the "Add Story" link
- Popup appears with node add form for Story
- I fill out form and click "Submit"
- Pop-up disappears and I see the "loading" animation for a few seconds.
- New pop-up appears with success message "Your Story has been created", but below the message is a blank Submit Page form - which I was in the middle of filling out on the source form.
- I close the popup, the drop-down list on the source form does not contain the newly added node as an option.
The module works amazingly on NEW Pages but not when editing EXISTING pages. From the looks of the other thread i referenced above, the problem exists in the "Add Page" link.
in my case the link is:
http://localhost/node/add/story?destination=node/add/page>
when I believe it should be:
http://localhost/node/add/story?destination=node/TheNodeNumber/edit>
Is there some function in the code to determine the source page's address before writing out the "Add Page" link?

#1
Correction: in the above issue, wherever i said "Add Page" i meant "Add Story"
#2
I can confirm that the module does in fact work properly when editing existing content if i use Firebug to change the "Add Story" link to something like
http://localhost/node/add/story?destination=node/22/edit(assuming node/22/edit was the page from which i called the popup form).
Upon examination of the module's code, it appears that line #87 is the creating the problem.
$links[] = l("Add ". $all_types[$type]->name, $path, array('class' => $pclass), "destination=node/add/" . strtr($src_type, '_', '-'));As you can see destination=node/add/ is hardcoded here. My thoughts are that the entire last part of line #87 should be replaced by the current url. The logic seems simple but i'm a novice at coding with php/drupal so I can't really say for sure.
Does this make sense to anyone else? I mean shouldn't clicking on the "Add xxx" link create a popup which, after you 'Submit' it, ALWAYS sends you back to the URL from which it was called? I'm going to start cutting my teeth on this bit of code. If anyone has any ideas or can suggest some functions i can use to get the source form's url and strip the base url from it, please let me know.
#3
Okay so i spent 10 minutes fixing the problem and 2 hours trying unsuccessfully to create a patch. grrrrr!
Here's the code: It starts at line #84. I added 1 line after line #86 and edited line #88 (which was previously line #87).
foreach ($field['referenceable_types'] as $type => $value) {if (!empty($value) && user_access("create $type content")) {
$path = "node/add/". strtr($type, '_', '-');
+ $url = $_GET['q'];
+ $links[] = l("Add ". $all_types[$type]->name, $path, array('class' => $pclass), "destination=$url");
- $links[] = l("Add ". $all_types[$type]->name, $path, array('class' => $pclass), "destination=node/add/" . strtr($src_type, '_', '-'));
}
So far it works great for creating a bug-free "Add xxxx" link both when ADDING and EDITING parent nodes. Someone should turn this into a patch if it helps them too...
#4
http://api.drupal.org/api/function/drupal_get_destination/5
Probably should just use drupal_get_destination() since that's what it's intended for I thinks:P.
ie
<?php+ $links[] = l("Add ". $all_types[$type]->name, $path, array('class' => $pclass), drupal_get_destination());
?>