I guess this is technically a feature request, but it seems like there should be a dropdown or other choice selector for filtering group content views by group audience. I couldn't find one.

Is OG missing this exposed filter widget, or did I just overlook how to implement it?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dpolant’s picture

I just wrote a handler to modify this behavior, if anyone wants it let me know. Maybe this should go into core. One thing I noticed was that og views api stuff is out of date and not functioning. OG stuff is available in views only through the field views API framework.

My handler works because I use views_data_alter on the og fields views data to swap in my custom handler.

amitaibu’s picture

> One thing I noticed was that og views api stuff is out of date

Can you provide a patch?

amitaibu’s picture

> One thing I noticed was that og views api stuff is out of date

Can you provide a patch?

mherchel’s picture

subscribe

amitaibu’s picture

Status: Active » Fixed
Issue tags: -filter, -dropdown, -Group Audience

Views integration was overhauled.

Status: Fixed » Closed (fixed)

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

logii’s picture

Status: Closed (fixed) » Active

Hi Amitaibu,
What do you mean by Views integration was overhauled? I'm still not able to create an exposed filter dropdown by group audience for group content.

mdroste’s picture

Maybe I miss something. I'm also not able to create an exposed filter dropdown by group audience for group content.

amitaibu’s picture

Title: There is no dropdown widget for filtering group content by group audience » Add widget for filtering group content by group audience in Views
Category: support » feature

> I'm also not able to create an exposed filter dropdown by group audience for group content.

There isn't a group list, you can filter by, only by the group ID. I'm willing to review a patch that will add such a list / autocomplete.

avr’s picture

The attached patch allows for a selecting groups when using the "Field: Groups audience:gid" field.

mdroste’s picture

I can't see any difference after the patch. There is still no dropdown as an exposed filter for groups.

avr’s picture

I've noticed in Views that I have to refresh/clear cache a few times to get the form to display as expected.

Here's a reroll of the patch. According to some inline documentation, it looks like the preferred method is to use the "Og membership" entity instead of the group_audience_gid field. So, to use this new patch:

1. Add a "Views Relationship" for "Group membership: Node group membership"
2. Add a filter field for "Og membership: group id" and use the new "Group" relationship

mdroste’s picture

@avr
Now it works. Great. Thanks for your work.

vikramy’s picture

Thanks avr for the patch.

It looks like this patch will not work with latest dev.
I am getting this error. "The operator is invalid on filter: OG membership: OG group gid".

pfrenssen’s picture

Status: Active » Needs review
FileSize
2.41 KB

Awesome, works great. The patch did not apply any more so I have updated it to the latest 7.x-1.x branch.

The terminology has also changed a bit in the latest versions, so here are some updated instructions on how to use this patch:

  1. Apply the patch.
  2. Clear the cache.
  3. Add the relationship "OG membership: OG membership from Node" to your view.
  4. Add the filter "OG membership: OG group gid" using the above relationship.
  5. Make sure the filter is exposed and that AJAX is enabled.
mwallenberg’s picture

Status: Needs review » Reviewed & tested by the community

I applied the patch in #16, and can confirm that it works. By now, there are a few features in the 7.x.1.x-dev branch that are not in 7.x-1.3. Maybe it is time for a 1.4 release?

eleonoreft’s picture

mwallenberg’s picture

Still working in 7.x-1.4.

bjlewis2’s picture

When I followed the steps above, I got this in the filter criteria:

(OG membership from node) Broken/missing handler (= )

And events that are posted to multiple groups show on the calendar 6 times (once for each group)

jessico’s picture

#16 patch worked great for me on OG version = "7.x-1.4". Thank you so much!

It would be great to see this feature rolled into the module.

amitaibu’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Reviewed & tested by the community » Needs work

Let's move it to 2.x. The filter should be adjusted to the fact we no longer have a single group, but different entities.

kclarkson’s picture

I too am looking for this feature.

Does this mean the patch must be updated to work with 2.x ?

Thanks,

avr’s picture

Here's a new version of the patch that applies to 7.x-2.x.

There is a TODO for adding an initial settings form in the handler to select both the state and the type of entity to be filtered.

The original instructions still apply:

  1. Create a new view
  2. Add a relationship of: "OG membership: OG membership from Node"
  3. Add a filter of: "OG membership: Group ID"

You should now have a select list instead of a plain text box. Exposing the filter works as expected.

avr’s picture

Status: Needs work » Needs review

Updating to "needs review"

amitaibu’s picture

The patch is against 1.x, no?

avr’s picture

This patch should be against 2.x. Just checked again - it applies. Perhaps I'm missing something?

amitaibu’s picture

Status: Needs review » Needs work

I think we should task another approach, in the line of EntityReferenceBehavior_ViewsFilterSelect::views_data_alter()

  • We should rely on user activating "Enable Render Views filters as select list" in the field settings
  • Add the group-audience field to the View -- up until here everything works ok, and you see the list of groups you may access.
  • Our code should alter the field handler to query the OG membership instead of looking directly at the empty field's table.

@avr, is it something you can investigate?

avr’s picture

Thanks for the feedback. I didn't even realize all of the changes that have been made to the field widget. That being said, I'm not familiar with how this should work - but I'll take some time to learn.

magtak’s picture

getting same as #20. Broken/missing handler.

iaminawe’s picture

The patch from #16 applies cleanly for me against 7.x-1.4 but it still appears as a text field and not as a dropdown. I have cleared my cache and am using a "OG membership from User" instead of from node on my view of users that I would like to filter by their respective groups. Ajax is enabled.

Any idea if this would need changing to work with a user relationship?

iaminawe’s picture

Sorry it was my fault - one of the patched files didnt upload. It works correctly thank you !

I do however receive this error using latest dev of Entity on this view

Notice: Trying to get property of non-object in entity_metadata_user_access() (line 626 of /usr/local/www/***/sites/all/modules/contrib/entity/modules/callbacks.inc).

Commenting the following lines 625 out worked for me but seems like it could have adverse effects on other permissions - can anyone cast an eye over this and let me know what implications commenting it out may have

// Grant access to the users own user account and to the anonymous one.
if (isset($entity) && $op != 'delete' && (($entity->uid == $account->uid && $entity->uid) || (!$entity->uid && $op == 'view'))) {
return TRUE;
}

sunildhimal’s picture

Status: Needs work » Needs review
amitaibu’s picture

Status: Needs review » Needs work

Please keep the status as is, #28

rocketeerbkw’s picture

@Amitaibu We should key off the same "Enable Render Views filters as select list" setting the entityreference already provides? I looked through the code but didn't see a way to Add/Override a behavior plugin to use the same settings checkbox for OG.

asioren’s picture

thanx so much for the patch! I applied the patch as the instructions above with new 7.x-2.0-beta3 version.
select list appears but I get an:
"No valid values found on filter: OG membership: Group ID." error.
is this because of the latest version or was the patch applied poorly?

Sherbet’s picture

Patch still applies to the latest 7.1 version that's out, but actually trying to run the filter from views gives a time-out error. Any idea why?

Premier Andrew’s picture

Patch applies fine, receive this message with 7.x-2.0-beta4: "Notice: Undefined index: gid in views_handler_filter->accept_exposed_input() (line 1260 of /sites/all/modules/views/handlers/views_handler_filter.inc)."

And broken/missing handler for the Filter by Group ID.

zengenuity’s picture

Status: Needs work » Needs review
FileSize
3.07 KB

Attached is a patch that adds the filter the way @Amitaibu suggested in #34. I'm pretty sure this is going to need some work, but I thought I would get things started. This works for me in the most typical case, but I'm not sure about some of the boundary cases and non-node group types. I also haven't checked access control. Someone with more OG code familiarity should review it.

This patch doesn't specifically check for the "render view filters as select" because I don't think it needs to. Even if that is turned off, the current textfield entityref filters don't work when you type in the entity_id. They do work once you apply this patch, as do the select filters.

In addition, after this patch, you can now use the og_group_ref field as an argument. Passing an NID in works as it should. I expect this is going to need some rework though, to make sure it's not too broad on entity type and obeys access control.

amitaibu’s picture

Status: Needs review » Needs work

Thanks for working on this zengenuity. Haven't tested but some review:

+++ b/plugins/entityreference/behavior/OgBehaviorHandler.class.phpundefined
@@ -162,4 +162,72 @@ class OgBehaviorHandler extends EntityReference_BehaviorHandler_Abstract {
+      if ($field['field_name'] == 'og_group_ref') {

Lets not hardcode the name. You can iterate over og_get_group_audience_fields()

+++ b/plugins/entityreference/behavior/OgBehaviorHandler.class.phpundefined
@@ -162,4 +162,72 @@ class OgBehaviorHandler extends EntityReference_BehaviorHandler_Abstract {
+              'node' => array(

This will also need to be removed. You can take the entity from the $field['settings']['target_type']

+++ b/plugins/entityreference/behavior/OgBehaviorHandler.class.phpundefined
@@ -162,4 +162,72 @@ class OgBehaviorHandler extends EntityReference_BehaviorHandler_Abstract {
+                'left_field' => 'nid',

Remove hardcode to nid. Use entity_info() to get the ID key.

Also can you add some comments about why you use "left_field".

zengenuity’s picture

Status: Needs work » Needs review
FileSize
2.44 KB

Reworked the patch to remove hard-coded values. This should work with any entity type and field. I've tested with the standard node and user fields, and those work. More exotic configs should work, but I haven't tested them.

A couple notes:
1. We don't need to iterate over og_get_group_audience_fields(), because this gets called one field at a time. I'm using og_is_group_audience_field() instead.
2. The table we're joining isn't for the entityref target type. It's actually the base table of whatever entity type the field is attached to. It's possible to pull this from $field['bundles'], so I'm getting it from there.

amitaibu’s picture

This looks really nice! I'm seeing an error when I enable Render Views filters as select list via admin/structure/types/manage/post/fields/og_group_ref, which is probably the last piece in the puzzle. Looking forward for your next patch :)

zengenuity’s picture

I just spent some time testing, and I don't see an error when I enable or disable Render Views and filters as select list. Can you give me more information?

amitaibu’s picture

Status: Needs review » Fixed

@zengenuity , re-tested and it worked fine. Might have been working on a wrong branch. Anyway, awesome work -- committed.

zengenuity’s picture

Thanks. I'm excited for this patch for the argument handling even more than the exposed filter. It's now possible to build a view that shows group content for a group without adding any relationships. Same with listing users in a group. One thing I should mention on that: my patch does not check that the state of the membership is 1. Adding that would be easy, but I found that I was able to use filters to limit by OG membership state, so it's more flexible to leave it out. Just making sure you're aware of it, in case it's an issue for you.

sportel’s picture

azinck’s picture

I haven't tested the patch (or dev version of the module) but how would Amitaibu feel about adding the ability to show group content AND the group node itself (maybe an option on the argument)? That's a problem I always run into. When users want a list of all content in a group they assume the group itself is a member of its own group.

I should add: thanks so much for your work, zengenuity!

sportel’s picture

I've been following this thread, because I want to be able to select from which group to show al users in a view. And so now that the patch (#41) has been committed, I updated OG and... no selectlist available when using an exposed filter for filtering groupmembership. So, I guess this patch does something else? Well, my bad understanding of the english language and/or drupal/og/views shows again (that happens sometimes:).
Anyway, is there a way to accomplish what I want (I've got a view which shows all users, and I'd like to filter by groupmembership)? Any help would be very much appreciated.

Thanks,

Mike.

zengenuity’s picture

@sportel: Make sure you have Render Views filters as select list checked in the field properties for the og_group_ref field.

@azinck: That's not going to be possible, because there's no entry in the og_membership table relating groups to themselves. You could use a Views attachment, where the attachment shows the group. Will force it to always be at the top, but it could work for certain circumstances.

azinck’s picture

Yeah, I know there's no entry in og_membership...wondering if we can't tweak the argument handler to do something clever with some extra logic in the join and/or where clause since we've now got our own custom argument handler... I've got to play with it a bit.

amitaibu’s picture

> Just making sure you're aware of it, in case it's an issue for you.

Yap, that's how it should work -- it should be configurable.

sportel’s picture

Thanks for your response. And forgive me for being such a noob, but I can't find the checkbox you mentioned.

I made a view based on Users. I didn't make any relationships. I've added the fields: User: Name and User: Picture. And I've added the filter: User: Groupmembership (og_user_node). I thought this would be the field where I should have the options you mentioned when I expose it. But I don't. I'm probably doing something wrong, but don't know what. Can you help me out?

Thanks,

Mike.

zengenuity’s picture

It's in the field settings for users. admin/config/people/accounts

The direct path to the field settings is: admin/config/people/accounts/fields/og_user_node

sportel’s picture

Thanks, works perfect!

I absolutely didn't think of checking out the fieldsetting on the useraccount form. Thanks.

Mike.

JuliaKoelsch’s picture

Would it be possible to add the patch from #16 to the 7.x.1.x branch? I've been using it since July, and now I have to reapply the patch after every module update.

Status: Fixed » Closed (fixed)

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

griz’s picture

Status: Closed (fixed) » Needs review

Bump.

griz’s picture

Status: Needs review » Closed (fixed)
preksha’s picture

Issue summary: View changes

Hi,

As per #16, it works by group id, not by group name. Also, I am not getting any drop down when I expose the filter.

Any one has an idea?

Alan D.’s picture

I just added a filter "Content: Groups audience (og_group_ref)", works without the relationship. Just remember to configure the field to show a select list.

preksha’s picture

@Alan

Yes, it works but need to configure the field to show a select list.

surendra77c’s picture

After applying the path please do the necessary setting in views :

1 .Under RELATIONSHIP ( add )
OG membership: OG membership from NODE

2.Under FILTER CRITERIA

(OG membership from node) OG
membership: Group ID (exposed)

Note : select the above (1) relationship in configuration of filter criteria

rv0’s picture

As Alan D says in above comment #60, no need to add any relationship, nor to use the group id field.

just the plain "content: group audience" field exposed, works like a charm.

David_Rothstein’s picture

Note: If you find that this feature isn't working for you - or if you find that you do in fact need to add a relationship to get it to work - you could be running into the problem in the linked issue. In any case, that issue is essentially a followup to fix a bug in this one.