Needs work
Project:
Content Construction Kit (CCK)
Version:
6.x-2.1
Component:
nodereference.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
12 Mar 2009 at 23:29 UTC
Updated:
15 Nov 2011 at 19:06 UTC
Jump to comment: Most recent file
Comments
Comment #1
RoboPhred commentedTurns out the reason it wasn't acting as I expected was due to faulty php-driven arguments in my view.
How would I pull the existing node (if any) for a view-populated-noderef? My goal is to prevent the noderef from selecting itself.
I poked at the arg() function, but the url only contains "nodereference/autocomplete/[field]/[entered value]"
Comment #2
RoboPhred commentedSo it turns out the main issue is specific to autocomplete fields. When using a list box, the arg() function can be used to pull the nid from the url just fine. Same when the autocomplete is validated.
The main issue, and what led me to believe this was a bug in autocomplete, is that the autocomplete uses its own menu callback and thus a different url. So while making an autocomplete that depends on an nid-aware view still "works" in that you cannot submit invalid (based on the nid) values, the autocomplete will still show them.
Since any solution to this would require the autocomplete being nid-aware, the best solution would probably be to append the nid (if any) on to the end of the autocomplete url and let others use views' default php argument. Extra points if views' default argument "Node ID from url" can work with it, but doubtful, as I assume that checks "arg(1) == 'node'".
The issue with this solution, however, is that there would now be two different places to read the Node ID from depending if the autocomplete is searching or validating...
Probably the cleanest solution, which would work for all content types, would be to provide a function similar to what views itself does, a cck_get_context() function which will return the current node (if any) that the view is being ran for.
I will try my hand at making a patch for this.
Comment #3
RoboPhred commentedI spent a few hours learning to do what turned out to be a very simple change.
This patch adds the nid to the autocomplete menu path, so the entire thing becomes "nodereference/autocomplete/[field]/[nid]"
If no node is defined, then the nid is set to 0.
This does not include the cck_get_context() function I mentioned above.
I would like some feedback on whether this is the correct way to go about solving this.
Comment #4
RoboPhred commentedComment #5
chichilatte commentedWorks perfectly for me, thank youuu! Two and a half years later :)
I'm using D6.22, Node Reference 6.x-2.9
One change though: in your View, the default argument should be PHP code...