it seems that og_get_group function removed from 7.x2-0 version
what's the equvilant for it?
i want to check current nid to see is it a group and if it is find the it's gid
thanks

UPDATE: The og_get_group function is not needed anymore. The group ID is equal to the node ID. If you have a node that belongs to a group, simply grab the og_group_ref nid values. Those are the groups themselves.

What did og_get_group() do in 7.x-1.x?

Given the entity id of a group content entity, we want to get the group entity this piece of content belongs to.
In og-7.x-1.x, the "group entity" was of a dedicated entity type "og group", associated with a group node, but not identical with it.

What do we want to achieve in 7.x-2.x where og_get_group() no longer exists?

In og-7.x-2.x, the "group entity" is the group node.
Given the entity id of a group content entity, we want to get the group entity this piece of content belongs to.
That is, we want to get the actual node that acts as an og group.

How to do that? (code example)

-- please complete --

Comments

amitaibu’s picture

Status: Active » Closed (duplicate)

Please search issue queue -- I've answered this question many times.

Renee S’s picture

When I search the issues queue for og_get_group, I find only this... Can you provide a link maybe to whatever duplicate you have in mind? Much appreciated!

donquixote’s picture

Status: Closed (duplicate) » Needs work

Indeed, finding this in the issue queue is not easy.
Even if it was answered multiple times, those issues probably lack the keywords to show up in search.

Can you post a link?
(and update the issue summary)

Thanks!

donquixote’s picture

I can't give a clear answer, but I made some progress.
People interested can steal some ideas from here, or correct me where I'm wrong.
#1819300: Support both branches of Organic Groups: 7.x-1.x and 7.x-2.x

amitaibu’s picture

@donquixote,
Since OG7-2.x the node ID == group ID, so there's no longer og_get_group(). This is why most OG API function now get also the $group_type as first parameter.

donquixote’s picture

Hm.
Actually I knew the first part of the answer.
But then somehow my brain (when writing #3) didn't want to make the obvious conclusions.

At least now we have this official answer for people coming from a search / Google.

Btw, I would be happy if you can cast an eye or two on the patch on Crumbs!

amitaibu’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

rar’s picture

Status: Closed (fixed) » Closed (won't fix)

> Please search issue queue -- I've answered this question many times.

Did you really? Then you should mark this as a duplicate of that earlier question not mark this as "closed: fixed" and provide a dead-end non-answer. I did a search and either your previous answer was deleted or it's not showing up anymore or drupal issue search is not effective. When I search for og_get_group, I get 26 issues and of those which seem roughly relevant, NONE contain your answer. I'm not the only one who's searched, as many other people in this issue have searched as well and stated that they can't find your answer either.

Drupoth10’s picture

I wholeheartedly agree. I've spent days looking through the issue queue, not to mention google and everywhere else and can't find an answer to this issue. When I comment out the line with the "og_get_group" function in it within the og_views.module file (as recommended here: https://drupal.org/node/1522026#comment-7823093), all of the published content from my entire website gets dumped into one of my groups, whereas my other groups are devoid of content now. Huge problem! Please be a kind soul and either post a link to your answer or re-publish your answer here, because it's nowhere to be found.

Drupoth10’s picture

Anyone??? This has really caused a mess for me and, from the looks of it, several other people. I've resorted to hacking the module, which isn't a good long-term solution. And anyway, even with my band-aid approach, I still can't get the OG views to work. Can someone throw us a bone?

Renee S’s picture

Drupoth, the answer is above, but a bit buried. It's not needed anymore because the group ID is equal to the node ID. If you have a node that belongs to a group, simply grab the og_group_ref values.

donquixote’s picture

Anyone who still remembers the details of this, could we add this to the issue summary?
(shame on me for not doing it myself, busy at this moment, and don't have it at the top of my head)

Drupoth10’s picture

Thanks for your reply, Renee S. I'm pretty new to Groups -- can you please explain in a little more detail what "grabbing the og_group_ref values" means? I think it might help other people in this discussion too.

Renee S’s picture

Drupoth10, assuming that this is being done programmatically since we're talking about functions: rather than calling the old function on the node id, use entity_metadata_wrapper or similar (see here: http://nikro.me/articles/professional/drupal-working-fields) to get the value of the node's og_group_ref field (or whatever you've called it if it's a custom field.)

Drupoth10’s picture

Renee S., I was trying to avoid doing this programmatically if possible. I've disabled the Groups Views module since it wasn't ported to Groups 7.x-2.x (I was getting the error about the depricated og_get_group function when that module was enabled). Since I'd like to avoid hacking the module if possible (though I guess it doesn't matter, since the Groups Views module probably won't be updated anymore), is there a way of doing this through the Views interface?

I've tried every combination of contextual filters and relationships you can imagine, and also used Viewfield to add a view to the "Groups" content type (that content type contains all of the "og_group_ref" and "og_roles_permissions"-type fields). And I set the argument of this new view to both [node:nid] and [user:uid]; But unfortunately, when I try all of these combinations, every post by every group member in every group is either showing up in evey one of my groups, or none of them are showing up anywhere, depending upon the filters I use, which are as follows:

For Contextual filters, I've tried both "OG membership: Entity id" and "OG membership: Group ID", configuring the "When the filter value is NOT available" section to "Provide default value, Current OG group from context" and making my "Group Type" the type "Node", which I've seen recommended many places, but it didn't work.

Then, for Relationships, I've tried "OG membership: OG membership from Node", "(OG membership from node) OG membership: Group Node from OG membership", "(Group node from OG membership) Entity Reference: Referencing entity", and everything in between.

If hacking the Groups Views module is the only way to accomplish what I need that's fine, but I feel in my gut that there must be a way to handle this through the View interface. Please let me know if I'm wrong. Thanks.

Drupoth10’s picture

Issue summary: View changes

Adding answer for those lost lambs who find this.

donquixote’s picture

I created a stub explanation in the issue summary. It would be great if someone could complete that.

Drupoth10’s picture

@ReneeS and @donquixote, I vaguely understand what you're getting at now, i.e. that the "group entity" is now the same thing as the group node, but I'm not sure where to plug in the entity_metadata_wrapper function in order to grab the og_group_ref values. Are you saying that I should replace the og_get_group function with the entity_metada_wrapper function in the og_view.module file? I'm sure there's more to it than this, but are you saying that instead of the following (part of the og_views_field_formatter_view function in the og_view.module):

$group = og_get_group($entity_type, $etid);
$element[0] = array('#markup' => views_embed_view($view[0], !empty($view[1]) ? $view[1] : 'default', !empty($group) ? $group->gid : ''));

I should instead write something like the following:

$entity_wrapper = entity_metadata_wrapper($entity_type, $etid);
$entity_wrapper->field_tags->set(array(1));

Or something? Any direction would be very welcome.

Renee S’s picture

@Drupoth10, OG2 has Views integration already, you just need to use relationships. You shouldn't need to change any code or use add-on modules to make it function. https://drupal.org/project/og_extras will give you a good working default view example you can use.

Drupoth10’s picture

@Renee S, thanks for your comment. I've been trying every relationship and contextual filter known to man (see #16 above) and I still can't make it work. I've tried mimicking the OG Extras default view example, with absolutely no luck (perhaps because the view I'm using for my groups' posts is a content pane, whereas the OG Extras default view example is in Page format). The result is that all of the posts from all of my groups are ending up in every single group (in other words, they're not being filtered correctly). Can you please give me a hint as to the relationships/contextual filter settings I should be using to allow posts to appear in the groups the authors of those posts belong to?

Renee S’s picture

@Drupoth10, have you tried with a hardcoded argument first, in the pane argument config? Make sure that works; I suspect the problem is where it's trying to get the argument from. Content ID should be it, and you might have to use path to get that. For a block on group content pages, you'll need a relationship to the entityreference field.

Drupoth10’s picture

@Renee S, thanks again for your comment. I have a silly question -- do I need to create a new view for every new group I create now that I've upgraded to 7.x-2.3? In the 7.x-1.x version, I just used one view to control the look of all of my groups. But now, no matter what I do, the one view (OG Content is what the view is called) seems to be repeated across all of my groups (i.e., no matter what relationships/contextual relationships combination I try, I get the same group content being posted in all of my groups). I'm starting to think I need to create a new view every time I create a new group, which would actually be more inconvenient than the previous version. Please let me know, and thanks again for your help.

Drupoth10’s picture

Issue summary: View changes

stub for a complete explanation in the issue summary.