Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently when using Rules with OG, if use the action 'Get group members from group audience' we will get a list of members which includes both pending and blocked users.
If we are using this action as part of a rule to send out content notifications, then this as bad as these notifications will be going to blocked and pending members. It's doubly bad if this is a private group.
I note in og_rules_action_info()
that this 'todo' has been noted:
function og_rules_action_info() {
$items = array();
$items['og_get_members'] = array(
'label' => t('Get group members from group audience'),
'group' => t('Organic groups'),
'parameter' => array(
'group_content' => array(
'type' => 'entity',
'label' => t('Group content'),
'description' => t('The group content determining the group audience.'),
),
// @todo: Add option to filter by member-state?
),
'provides' => array(
'group_members' => array('type' => 'list<user>', 'label' => t('List of group members')),
),
'base' => 'og_rules_get_members',
'access callback' => 'og_rules_integration_access',
);
Has there been any work towards completing this todo? If not, I'm happy to have a stab. Any pointers as to how best to go about this?
Comments
Comment #1
torrance123 CreditAttribution: torrance123 commentedPlease see attached patch of my first attempt.
This is against OG 7.x-2.x HEAD but it looks like it could be patched against OG 1.x too without issue.
Comment #2
amitaibuIn 2.x you can already filter by member state using the wrapper (which should be exposed to Rules). For example --
$wrapper->{'og_membership__' . OG_STATE_ACTIVE}->value();
See og_entity_property_info()
Comment #3
torrance123 CreditAttribution: torrance123 commentedHi Amitaibu,
I'm confused. Are you suggesting I alter the patch to use the wrapper, or are you suggesting that the patch is unnecessary/the wrong way and the use case should be addressed by 'exposing' the wrapper to Rules?
Either way, our issue with the "Get group members from group audience" action appears to still remain — I don't think this is 'fixed'.
I'm still keen to make this work for us, but I need a little more guidance than looking at the code of
og_entity_property_info()
.Comment #4
torrance123 CreditAttribution: torrance123 commentedOr by this do you mean it's already possible to do this in Rules? I can see that I can filter og_membership by state, however the rule "Get group members from group audience" loads up users, not og_membership entities, and I'm not at all sure how to inject a state filter into that pipeline.
Comment #5
dooleysarahe CreditAttribution: dooleysarahe commentedDid anything ever come of this? I am trying to figure out how to do the same thing.
Comment #6
jojonaloha CreditAttribution: jojonaloha commentedI think torrance123 is right, I can't figure out how to do this through Rules UI at all. I've attached an updated patch that also adds the ability to filter by the Role in the group when getting a list of members.
Once you apply the patch, there are two new options in the "Get group members from group audience" action to filter the member list "Membership States" (thanks to torrance123) and "Group Roles".
Comment #7
shushu CreditAttribution: shushu commentedI think the feature request is decent, and checking the patch it seems to work as expected.
I think adding a "negative" checkbox to the "Membership states" condition will even make it stronger.
@jojonaloha, can you please add it ?
Comment #8
jojonaloha CreditAttribution: jojonaloha commentedI added two checkbox options for the action to allow loading users not in the selected state and/or not in the selected roles.
I also noticed a missing t() call in my previous patch.
Comment #9
shushu CreditAttribution: shushu commentedTested with several of the different options, all seems to work as expected.
Comment #10
Marko B CreditAttribution: Marko B commentedA Little hijack (sorry) but I when I use this action, I can't find proper data selector and nobody is mentioning this, I am trying og-membership:group but I get Unable to get variable group_members, it is not defined.
Comment #11
Marko B CreditAttribution: Marko B commentedSeems that [og-membership:entity] is the answer I was looking for. But please tell me if I am doing it wrong. sorry for inconvenience.
Comment #12
ZenLax CreditAttribution: ZenLax commentedSaved my bacon. THANK YOU!!!
Comment #13
gatorjoe CreditAttribution: gatorjoe commented#8 works perfectly for me. Thank you!
Comment #14
tony.herr CreditAttribution: tony.herr commentedHas this patch been incorporated into any release yet?
Comment #15
travelerttPatch #8 works for us.
Comment #17
jojonaloha CreditAttribution: jojonaloha at Metal Toad commentedSorry for adding new features to an existing issue. I would create a new issue but it would require this patch to be committed first. I also would not like to have this patch hold up #8 from being committed.
The new patch adds the ability to filter by User role as well, not just the group membership role. It could also be that we could do this another way in Rules.
Leaving in RTBC for #8. Will open a new issue if it gets committed.
Comment #19
dureaghin CreditAttribution: dureaghin commentedPatch #8 works for us too. Thanks.
Comment #20
kyledesu CreditAttribution: kyledesu commentedI haven't been successful on getting 8 to work on mine it still continues to pull all members.
Comment #21
aperedos CreditAttribution: aperedos commentedPatch #17 works for me. Thanks
Comment #22
Jan-E CreditAttribution: Jan-E commentedFWIW: I re-applied patch #8 to OG 7.x-2.11.