I just managed to track down an issue that has been bugging me for a couple of hours. It appears that when a new og node with a parent og node is inserted the tokens that govern the path (specifically those that look at the parent group) are not being populated. What this means is that if a group is being inserted, and a parent group has been set, then the path generated for that group will not contain the parent group. Everything functions fine when updating the same node.
From my limited knowledge of the inner workings of the module I think that the module is trying to fetch the parent group for the current group being inserted, but that this data doesn't exist yet so it is returning blank values. This seems to be the case as inspecting the og_parent value during a node insert shows that this value is an integer, which suggests it hasn't been written to the db yet. There are also a few errors being generated as properties of non-existent objects are accessed.
For my current project I have bypassed this problem so that if the parent hasn't been found then force load the data from the og_parent nid in the current group. I basically inserted the following code into link 37 of og_subgroups/includes/token.inc
$parent = og_subgroups_get_group_parent($node);
$grandparent = $parent ? og_subgroups_get_group_parent($parent) : NULL;
// If the parent is null then force it not to be by loading it from the node data
if (is_null($parent)) {
if (is_numeric($node->og_parent)) {
$node->og_parent = node_load($node->og_parent);
}
if (isset($node->og_parent->nid)) {
$parent = $node->og_parent;
$grandparent = $parent;
}
}
Note that this works for me because I only have one level of groups in my project and I therefore don't need the grandparent object to be different to the parent. I thought this might help anyone else with the same issue. :)
Comments
Comment #1
bschilt commentedI poked around and was able to recreate the issue that you're having. When a node is inserted, the Token module runs first and gets the values for the tokens, then the og_subgroups_nodeapi() function is called, which is where the the group gets added to the tree.
Sooo, not sure at this point how to get the values to populate in the tokens during node creation.
To recreate the issue, I was using the Automatic Node Titles module and I used the [subgroups-parent] token in the title of the new node.
Re-saving the node (edit mode) fixes the title, but that's not a good long term solution.
Comment #2
christopherreay commented@PhilipNorton:m THANKS for this, saved me ooodles of time. Really appreciated ++
There are some other, similar issues with og_subgroups we coudl attack together!T
Comment #3
bschilt commented@christopherreay
What are the other issues that you speak of? If they have not been documented in an issue ticket already can you please do so? I've got some time coming up that I can spend on the issue queue.