Hi
I was wondering if it is possible to load the parent nodes of a child node. Basically, the reverse of the nodefamily_relation_load() function. I'm trying to create tabbed navigation of different cck content types. I have usernode->profile_a and profile_a->profile_b relations set up with node family. If I'm displaying the page for profile_a, I can load the nodes of the children of profile_a and provide links to those children. However, if I'm looking at the node profile_b, it's not obvious to me how I can determine which nodes are parents of profile_b so that I can also provide links to them.
Thanks for any help you can provide
AC
Comments
Comment #1
fagoI've added the following function (to 4.7 and HEAD) for this purpose:
Would be cool if you could publish your node-loading solution for the tabs, because this is a often requested feature.
Comment #2
aclight commentedThanks for adding this function. I will test it soon to see if this gives me what I need (I think it will). Once I get the tab stuff working, I'll post the solution so others can see. There are a few other difficulties I'm having getting tabs to work like I want--maybe you will have suggestions.
Once again, thanks for adding that function. I'll let you know how it works.
AC
Comment #3
fagowhat about using the readable name of the content-type?
you can get it by using a code similar to:
Comment #4
aclight commentedThanks for the idea of using node_get_types(). That works and I hadn't thought of trying that.
Regarding the new function you added, I changed it a little to better match the output of nodefamily_relation_load(). The function now returns the actual loaded nodes, and not just the nids. Here's the changed function:
I also created a new function that loads the sibling nodes of a given node. I needed this for the tab theming to work. There are still other circumstances where the tabbed theming won't work as I'm doing it (eg. if there are grandchildren/grandparent or cousin or children of a sibling node relations in nodefamily). I think it would be best if the relationship discovery was done in the nodefamily module instead of the theme, since that is more flexible. Maybe you would want to create a function that returns an array containing the entire relationship of a family of nodes, including the current node.
Anyway, here is the new function I wrote (based on the parent and children functions).
The other issue with regards to creating tabs that I'm running into is that the order of the children/parents returned isn't the same every time for every node. It would be helpful if there was some way to set the weight of nodes at the same level of a family. That way, the output of the relationship discovery functions could be sorted by the weights. Right now I'm just doing a
if ($children) sort($children);operation on the output of the relationship functions, but that doesn't always give me the order I want them to be in.
Last issue with regards to tabbing--is it possible to change the display title of 'Usernode' to something else?
Thanks for all of your help on this issue. I've almost got this working like I had hoped it would.
AC
Comment #5
fagothanks for your code.
I've changed the parents loading function accordingly and added a function for loading siblings, that works similar as yours, but reuses the other loading functions and groups the output by parent nodeid, because there might be multiple parents.
http://cvs.drupal.org/viewcvs/drupal/contributions/modules/nodefamily/no...
Regarding the ordering: You can use the load_by_type function to get an array grouped by content types, which should solve all ordering troubles as long as you have only one node per content type.
Comment #6
mtk commentedI was looking for such a solution all over this forum...
I've downloaded latest release, but I get an empty array running both:
&
from a node-content_mycontent.tpl.php...
what did I do wring?
Comment #7
fagoI suppose your node has no nodefamily relation? -> goto admin settings nodefamily and verify your settings
Comment #8
aclight commentedI tried using the most recent version of nodefamily.module (17Nov06) and I'm getting a recursion warning from PHP when I do
I won't reproduce the entire printout here, but my nodefamily structure is:
usernode->node_a
usernode->node_b
When getting the parents of node_a, the output includes the children of the parent usernode, which includes node_a, and thus triggers the recursion.
I'm assuming this is something that should be fixed, though it doesn't appear to cause any actual problems since it's caught by PHP.
Thanks
AC
Comment #9
fagostrange, for me this functions are working fine! (php5.2)
What php version are you using? Can you post the error?
I don't see where recursion should occur here, the function just loads the parents and returns them. Presumable there must be a problem with the node-id detection code.
Do you have troubles with all loading functions?
Comment #10
aclight commentedI'm using PHP 5.0.4.
I'll paste some information below. Let me explain it first. I'm viewing content type content_user_profile (node 484). In my template file for that type of content, I have the lines:
When I view that page, I get the output below. Note that I have removed some information that is not relevant for security/privacy purposes. You can see the recursion warning towards the middle of the output. I will try some of the other functions and get back with you as to whether all functions cause this. Also, just so it's clear, my node family relationships are:
Comment #11
fagoyeah, I think I know whats happening.
could you try the latest development snapshot of drupal 4.7.x?
http://drupal.org/node/3060/release
I think this problem should be fixed there. (node_load() & php5 object references..)
Comment #12
aclight commentedyeah, it's definitely related to passing nodes by reference. It may be a bit before I can try the development version to see if that fixes the problem, but I'm assuming you are referring to http://drupal.org/node/86842 as the problem, and I read that thread and it looks like that would fix the problem. I'll let you know when I get a chance to test it.
Thanks
AC
Comment #13
fagoyep, that's what I meant.
Comment #14
fagoplease open another issue for this, if it isn't fixed with that.
Comment #15
mtk commentedI suppose your node has no nodefamily relation? -> goto admin settings nodefamily and verify your settings
actually I didn't have a parent...
I was able to create a child without its parent.
is there a way to block this?
Comment #16
(not verified) commented