Attached is a patch for adding in the parent/source node nid into the view for the CCK field. I didn't want to go through the hassle of adding a new nodereference field pointing back to the parent and the wiring involved. This seemed the easiest and doesn't seem to affect anything... handy too.
| Comment | File | Size | Author |
|---|---|---|---|
| nodereference_views_parent_ref.patch | 618 bytes | dayre |
Comments
Comment #1
joachim commentedI understand the patch but I don't understand its reasons -- what does this allow you to achieve?
Comment #2
dayre commentedIn my case, I have a parent content type with a node reference field containing a collection of child content types.
I don't require an additional node reference from child back to parent in my application as it is redundant and would require extra logic or a module to maintain parent->child and child->parent references during adds/updates. My users are always going to be working with the parent nodes and attaching child nodes... they will never be working with child nodes directly and hooking up to parent nodes.
In my template for the parent content type, i'm using your module to display the list of child nodes using a view.... but in the template for the view listing the child nodes, i don't have any reference to the parent/containing node ID which I need in order to construct a URL that is needed further along in my application's workflow.
In order to get the node ID of the containing parent node in the view template that lists the child nodes, there are only two options:
1) add a node reference field to the child content type to store a parent reference. I could then add this parent field to the child view and use it in the child view template. This would work, but for the reasons above... it's overly complicated.
2) pass the NID of the parent/containing node into the view for the child nodes as an additional/second argument which this patch does.
#2 was a far simpler way to go for what i was doing. I don't have to maintain another node reference in the child.
This module is great in that it allows you to use views to render node references... but it seems logical to me that the view should be given two arguments... 1) the list of NIDs the view can use and 2) the NID of the node that contains that particular node reference field.
Hope this makes it clearer.
Comment #3
joachim commentedAh.... now I get it :)
I've committed a modified version of your patch:
- added a null argument to the default view (in case users re-use their views, and want to give it arguments to use elsewhere, and then find their node display is being weird...)
- I'm pretty much it's safe to assume $element will always have a #node key.
Grab it from the dev release when it's updated and give it a spin.
Thanks for the patch :)
Comment #4
bomarmonk commentedDevelopment version of module is not available. Can you make sure the development version gets tarballed, as I would like to use this functionality with the modifications you have made.
Comment #5
bomarmonk commentedSince the tarball isn't rolled, I went ahead and downloaded the latest files manually from CVS. Unfortunately, I can't seem to get this feature to work. I have a parent node that can have many children. I am simply trying to show all of the children, with a node reference view, on the parent node. This module seems especially well suited to accomplish this, but I can't get it to work. I don't see the parent NID as an option in my view and I can't get the view to display the children for a specific parent NID (just in testing the view, let alone getting the "view" of the field to display the view. Any help would be greatly appreciated. Thanks again for the great module. It really could help me out!
Comment #6
bomarmonk commentedOkay, I managed to get the view to show the child or referenced node for the parent (simply by adding the node reference field to the "fields" for my view). Simple, but is this something that should be explained in the docs for this module? I'm not sure. However, I am still having trouble getting this view to replace the actual display of the field-view. In my content template, I've simply typed:
<?php print $node->field_location_reference[0]['view'] ?>. Since I have chosen the "view" option for the node reference field and named my field the same as the view, I'm expecting this to work. What am I missing? Again, thank you for any help here.Comment #7
joachim commented@bomarmonk: I'm not sure your problem is related to the feature this issue covers. If that's the case, please could you file a new issue?
You don't need nodereference fields: you need the Node: Nid argument that comes in the default view.
Comment #9
tallsimon commentedfor those looking to do this without an extra module see http://drupal.org/node/697506#comment-2528406
Comment #10
summit commentedBookmarking, greetings, Martijn