Posted by Les Lim on August 3, 2011 at 2:33pm
28 followers
| Project: | Organic groups |
| Version: | 7.x-1.3 |
| Component: | Og Views |
| Category: | support request |
| Priority: | major |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
I've got a view of nodes that I'm trying to filter based on a property of the group node associated with each node, but I can't build the proper chain of relationships in Views. I can relate the node to its group membership entity, and in turn relate the membership entity to its group entity, but there doesn't seem to be a way to relate the group entity to the group node.
Am I going about this all wrong?
Comments
#1
I'd like to do the same thing. To me, the relationships seem obvious, but I don't think views can recognize them.
#2
Same here. Would like to list group posts and group entity titles in same table.
#3
This issue states that it is possible... #1006860: Allow views 'relationships' from group to group type and from group content type to group Will try to test, but I'm sceptical since I have tried to do it for 3 hours :)
#4
@mansspams
The issue here is that the relationship is one-way. You can get the group from the entity, but you cannot get the entity from the group. For most people, it's probably not a problem unless they need to go from group to node to group in their relationships (like me, urgh :$)
If you check the og page, there's a video by bjlewis2 on how to do what you want. It's a great walkthrough.
Linking again for convenience. http://modulesunraveled.com/organic-groups
To me though, it seems like this issue is going to be postponed until a general Entity API solution is found. I would check the issue queue there for progress.
#5
I was thinking that if there is a database table where both values are in same row, there should not be big problem to create relationships both ways and there is table 'og_membership' with all the info needed. How I wish I could write code better :(
#6
@mansspams,
Can you show a short table of the data you want to present, as example, to better understand you needs.
#7
I have a view listing group post node titles in column A and I want to add column B with group node titles. How to set up relationships for this view? In perfect world from group post node I would make relationship #1 to group and relationship #2 to group node. In result I would be able to add title (or any other field from group node) and just select last relationship in display settings and views would display it in column B. All this should happen without Contextual filters.
Without it I have to do terrible things and kill kittens (like writting
$result = db_query("SELECT etid FROM {og} WHERE gid = :gid", array(':gid' => trim($content['gid'])));where $content['gid'] is HTML outputted by views) in theme just to demonstrate og in site ;)#8
Here is visualization of that table...
#9
Ah, then yes, you have the same node -> group -> node problem as me.
@Amitaibu
This would be a bit of work, but why not create a dependency using Relation (http://drupal.org/project/Relation) an Entity Reference Field (http://drupal.org/project/ref_field) to build the relationships? Seems like it would save you effort in the long run, since OG Views would become obsolete.
#10
I'm stuck here too and the ability to do a view of group content that includes both the group page node and the 'parent' group node seems like an obvious need. I have a 'group' content type that is the group entity. I have pages in the groups that are other content types. I need to display some information from the 'group' in a view of the pages. In this particular case, the group has an image field and I want that image displayed in a view of the group pages. The only workaround I've come up with is to go into the node view using hook_preprocess_node and add information from the parent group to the $variables, then create a custom node template that displays them. But that is a lot of work and it doesn't help on a view of fields, which is what I really need. This was easy to do in D6, so it feels like a regression that it can't be done in D7.
Not sure how to solve the problem though. It feels like the 'og' relationship should behave like the nodereference field relationship to join in the tables we need and make them available as sources for fields and filters, so you can say you want to see the title or some other field from the group entity brought in by the OG relationship.
#11
After fighting for hours with all the relationships, I'm relieved to hear it's not just me.
#12
Not sure if this is still a support request, but leaving for now.
#13
> This was easy to do in D6, so it feels like a regression that it can't be done in D7.
Indeed. This is because, unlike D6, OG group and OG membership are different entities. I think what is missing is a reverse relationship, (i.e. get node from group) -- it probably should go in og_views_data_alter(), although the best thing would have been able to get this automatically via entity-metadata - maybe improving #1066398: Reverse entity relationships for Views integration
#14
yeah, the current D7 OG Views integration is much less powerful than the D6 one. Therefore, I change the issue to feature request.
#15
I was thinking the same thing, a variation of views_handler_relationship_entity_reverse. We can't use that because it is very field-specific, but something like that to bring the reverse relationships into a view is what we want I think. I poked around with it but didn't get anything actually working. The code to look at as an example is in Views, in views/modules/field/views_handler_relationship_entity_reverse.inc.
#16
Or yes, somehow getting this automatically through Entity API. But I wasn't able to figure out what was needed there either :(
#17
I created an issue in Entity API. See the response here: #1288844: Merge Relation with Entity API. Is there a proper implementation of entity-property-info in OG?
#18
subscribe
#19
sub
#20
@Amitaibu
Since #1066398: Reverse entity relationships for Views integration was committed, any chance of seeing the effects in OG?
#21
Ran into this issue too while upgrading a - D5, skipping D6 :) - site.
/Edit
Getting this to work is actually pretty tricky. Any entity type can potentially be a group. Entity types have their own base table however, so a simple reverse relationship isn't going to work.
/Edit
Or maybe it does. just add relationships for every entity type that is a group (has a group field).
#22
Something like this? In most cases you need to setup multiple relations for it to be useful.
#23
Also, if anyone is interested in a temporary hack, here's the relationship code for Group to Node only. Paste it in og.views.inc in the og_views_data_alter() function after
// TODO: This should be handled by entity-metadata.foreach (entity_get_info() as $entity_type => $info) {
if (!empty($info['fieldable'])) {
Temporary code:
// Reverse group-to-node relationship.if ($entity_type == 'node') {
$title = t('Reverse @entity group', array('@entity' => ucfirst($info['label'])));
$help = t('Add information on the base @entity from the group.', array('@entity' => ucfirst($info['label'])));
$data['og']['reverse_og_rel'] = array(
'group' => t('Group'),
'title' => $title,
'help' => $help,
'relationship' => array(
// Pass the entity to the handler.
'entity' => 'og',
'handler' => 'views_handler_relationship',
'label' => t($info['label']),
'base' => $entity_type,
'base field' => $info['entity keys']['id'],
'relationship field' => 'etid',
),
);
}
Would always prefer to have Entity API take this over.
#24
whoops. I guess we decided to fix this at the same time! I like the $is_group_type check.
#25
tested patch in #22 and worked fine.
#26
Briefly tested #22 in a simple environment with only a single group type - worked fine for both User membership views and Node membership views. Haven't tested any more complex configurations. Nice work!
Structurally, I don't see any reason why we couldn't place the relationship definition within the foreach loop.
#27
Thanks casey.
+++ b/includes/og.views.incundefined@@ -134,6 +134,30 @@
+ $is_group_type = FALSE;
+ foreach ($info['bundles'] as $bundle_name => $bundle_info) {
+ if (og_is_group_type($entity_type, $bundle_name)) {
+ $is_group_type = TRUE;
+ break;
+ }
Instead of this check you can use og_get_all_group_entity().
+++ b/includes/og.views.incundefined@@ -134,6 +134,30 @@
+ 'help' => t('TODO'),
Maybe: Relate an entity to its group entity.
#28
We should do the same thing for group membership info too. Might be a bit harder because you can have both nodes and users.
#29
I'm sorry to say I don't think the patches are working for me. I keep getting "There is no content in this group."
#30
#22 works for me.
Look for a relationship on the "group membership" relationship with a "TODO" description.
Then you can add arguments or fields as needed from the source entity.
#31
Reroll of #22 with the feedback from #27.
#32
The patch in #31 works for me. For others trying to reproduce, these were the steps I followed:
The result was that I could feed the view a group id and get the group node entity in return. Thanks!
#33
Committed, thanks.
I wonder if it helps achieving #8, though.
#34
It seems too hard to tell views the "GID". Glad to see the patch, I will try it asap.
#35
Automatically closed -- issue fixed for 2 weeks with no activity.
#36
This has saved my bacon, big time! Thank you so much @casey and @tim.plunkett!!!
#37
Can we add the membership->user relationship too?
#38
That's super cool addition to og, but it required me 1 hour to figure out how to fetch og group title, taking into account my 5 year experience with views
(I was building very simple view: group post title / group title - but I needed to list posts only from groups of node type "corporate blog" )
I had to enable views sql debug to figure out the final mix of relationships:
1) OG membership: OG membership from Node
2) (OG membership from node) OG membership: OG group gid
3) (OG group) OG group: Node from OG group
I hope that helps somebody who finds the topic.
may be it's just not my day, but I really think this is something impossible for ordinary user to figure out without step-by-step manuals.
#39
well, for the advanced usage like this, the site builder needs to understand database. It's not built for ordinary users.
#40
Is there any way to use the method in #38 to get additional fields from the group? I've created my groups such that I'm using a building ID for the group title, then an additional field called Building Name. I'd like to get both fields into my view, but this method only exposes the building ID in the form of (OG group) OG group: Label.
The odd part is that in the list of Content fields both Content: Group and Content: Building Name fields are available even without the relationship. However, neither of them actually display any data (with or without the relationships).
#41
Thank you "restyler" for your method in ( #38).
Your relationship chain worked fine for me.
I've been trying to do that all day long and was really starting to doubt it was possible in the views UI.
Thanks for sharing
#42
#31 worked for me although my relationships looked like this.
Group membership: Node group membership
(group membership) OG membership: Group gid
(OG group) Group: Node being the group
#43
#31
Worked for me.
We have companies content type set as groups and then diff entities linking to the groups.
I needed to show in a view a table with content from the company node + article node
So now I'm able to set the relationship from my article all the way up to the group and also get the group node information, then I can set the fields as being from the company instead of from the article content type.
My relationships:
Group membership: Content group membership
(group membership from article doc) OG membership: Group gid
(OG group company where article belongs) Group: Content being the group
Thank you again guys!
#44
has this gotten lost/broken in 2.x?
i simply want to know the group my post is located in. i no longer see Group: Node relationships but do have Entity Relationships like: A bridge to the Content entity that is referenced via og_group_ref
but this doesn't seem to do anything.
#45
@liquidcms
Can you please provide some more information.
In 2.x the views setting will look like this:
Contextual filters
(Group node from OG membership) Content: Nid
Relationships
OG membership: OG membership from Node
(group membership) OG membership: Group Node from OG membership
#46
No bug
#47
@DruDoc, yes, that's part of the trick, thanks.. didn't realize that since going to 2.x the relationships are now hierarchical? so don't see the 2nd set until i add OG membership: OG membership from Node
also, for the case i was asking about... how to know a group content node's group node, i think the contextual filter part is just:
Content: Nid
not:
(Group node from OG membership) Content: Nid
since i am on the node not the group.
but, this still isn't complete if i want to recreate the simple block that came with D6 which is list group content creation links "within" a group since this only works on group content nodes; doesn't work on the actual group node itself.. i guess i need an OR in here somewhere.
and of course i'd still need a way to list all content types that can be added to a group.. ugghh.. probably still just easier to do this in code (and replicate the code that came with D6)
i am sure i am still getting accustomed to D7 OG; but wow.. this sure is much more convoluted than in D6.
i'll leave this as fixed as this was original question i believe and i do see now "how to get group from a group content node"; but real question should have been simply; how to tell group context? (which in D6 was known on group content or the group node itself)
#48
so, is the "bug" here simply that this relationship: OG membership: OG membership from Node fails on the Group node?
in other words should the group node not be a member of the group?
#49
The screenshot might help :)
#50
since this works for group content nodes (but not group nodes); i'll raise a separate issue for that.
#51
I was using #38 relationship chain succesfully until something broke :
1) OG membership: OG membership from Node
2) (OG membership from node) OG membership: OG group gid
3) (OG group) OG group: Node from OG group
I now have the following error in the views UI:
1) OG membership: OG membership from Node
2) (OG membership from node) OG membership: OG group gid
3) (Groupe OG) Broken/missing handler
For some reason the 'Node from OG group' relationship does not appear in the list anymore.
I know someone else has made changes on that site (maybe a og update, it's now 7x-1.3 version in used )
Does someone knows witch version of OG GROUP I should use to find this relation back ?
#52
Same problem here....
#53
#45 can't get it to work in content pane. Any help? My goal is to display a list of other group content posts under the same group when viewing a group content.
using og 7.x-2.x-dev
View content pane setting
Contextual filters
(Group node from OG membership) Content: Nid
Relationships
OG membership: OG membership from Node
(OG membership from node) OG membership: Group Node from OG membership
Argument input
Content: Nid source = From context
Required context = Node - Content ID
===========================
Panes Node template setting
Selection rule = OG: Node is an OG group content
#54
@spacereactor
In panel relationships add "Node from Node (on Node: Group membership [og_group_ref])" and select this relationship for providing the context.
You only need these in your pane views:
Contextual filters
(OG membership from node) OG membership: Group ID
Relationships
OG membership: OG membership from Node
and Argument input: from context - node: Content ID
#55
Thank DruDoc I manage to display other group post but it also display the current node content in the group content display twice.
I try to add another Contextual filters to exclude the current node but it doesn't work
#56
In the pane view, did you filter by content type (
Filter criteria
Content: Published (Yes)
Content: Type (= Your Group content(s))
#57
Automatically closed -- issue fixed for 2 weeks with no activity.
#58
Hi,
I have the same problem here I am trying to show all the content list and showing the group id/ group name the contents are associated too, I have been trying for hours and finally it is showing I am using the Group membership: Node group membership relationships and I managed to show the (group membership) OG membership: Group gid field. I am using 7.x-1.3 version.
one bug or problem I am facing, if in the content type for that field I enabled the entity translation :
Field translation:
This field is shared among the entity translations. Enable translation
suddenly all the gid's disappeared when I do the new creations/update the content.. but when I disable the translation fields in the content type for that field, when I do the content update it is back again.
I can not get this to work? can someone please lead the way. I am trying to achieve showing list of node filter by content type and by groups they are associated and when user change language it will show the translated content in the correct groups.
I am attaching the screenshot of my config.
thank you
#59
Hi,
I have the same problem here I am trying to show all the content list and showing the group id/ group name the contents are associated too, I have been trying for hours and finally it is showing I am using the Group membership: Node group membership relationships and I managed to show the (group membership) OG membership: Group gid field. I am using 7.x-1.3 version.
one bug or problem I am facing, if in the content type for that field I enabled the entity translation :
Field translation:
This field is shared among the entity translations. Enable translation
suddenly all the gid's disappeared when I do the new creations/update the content.. but when I disable the translation fields in the content type for that field, when I do the content update it is back again.
I can not get this to work? can someone please lead the way. I am trying to achieve showing list of node filter by content type and by groups they are associated and when user change language it will show the translated content in the correct groups.
I am attaching the screenshot of my config.
#60
@boby
there is no contextual filter selected in your views.
#61
Hi DruDoc,
I need to list them without using contextual filter? can I do that?
thank you
#62
Of course you can do that, but it means that your issue is probably not related to the original issue posted here. May be you should start a new issue. I do not have any idea about 'entity translation'. Could this be an issue with that module?
#63
let me recreate the new issues, I don't really understand is it related or not, what I can check is, if it is translated using the field translation, then the results will have ['und'] for the language, and if it is translated, then it will have ['en'], and then the views will stop working. it will not pull any results of the group id anymore.