Hi,

I'm looking for an option to limit the Group Audience select list af a view it's (exposed) filter. I could find any suggestions in the documentation so I'm wondering if it is possible.

Example:
My groups: (A, B, C, D)
My User: X, Y
Membership: X --> A/B | Y --> C/D

Exposed view is now showing A,B,C,D for both users, instead in my case User X should only be able te filter (A,B) and User Y (C,D)

Any suggestions?

Thanks in advance.

Comments

danyll’s picture

Did you manage to do it @kaho-kim?

kirankkaran’s picture

Hi Folks,

I have a similar case. When I log on to a group page, I have a link for creating group post. On clicking the group post I am opening the group post form in a popup. What I want is that When I save the group post I want to save it to the current group which I am viewing.
Any one has any idea?

akolahi’s picture

Hi, You want something like this that will filter the list based on the the groups the user actually belongs to:

 function MY_MODULE_form_views_exposed_form_alter(&$form, $form_state, $form_id){
  //checks the form id
  if($form['#id'] == 'views-exposed-form-YOUR-VIEWS-FORM-ID'){
    // prevent recursion - only execute once on first run through
    static $called = 0;
    $called++;
    //only do first time through
    if ($called == 1) {
	//dsm($form);
	
	global $user;
	if ($user->uid) {
	$gid = og_get_groups_by_user($user);
	$dropdown_array = [];
	
	$dropdown_array['All'] = "- Any -";
	
	foreach ($gid['node'] as $key => $value) {
		$og_node = node_load($value);
		$og_name = $og_node->title;
		$key = $value;
		$value = $og_name;
		$dropdown_array[$key] = $value;
   }
   
    asort($dropdown_array);
	$form['og_group_ref_target_id']['#options'] = $dropdown_array;
	
    }
	}
  }
}