I'm trying to set up a Rule to send a privatemsg to all group members when someone posts a comment on the group node itself.
One approach I've tried using existing options provided by the OG module:
**Events** After saving a new comment **Conditions** Entity is a group Parameter: Entity: [comment:node] **Actions** Get group members from group audience Parameter: Group content: [comment:node] Provides variables: List of group members (group_members) Loop Parameter: List: [group_members] List item: Current member (member) **Loop actions**
This method fails to find any members. I'm guessing this is because the "Get group members from group audience" function expects its parameter to be a node posted on the group rather than the node representing the group itself.
Another method I've tried is to define a new Rules action in a custom module:
/**
* Implements hook_rules_action_info
*/
function mymodule_rules_action_info()
{
return array(
'mymodule_get_og_members' => array(
'label' => t( 'Get OG members from group node' ),
'group' => t( 'Custom' ),
'parameter' => array(
'nid' => array(
'label' => t( 'Group node NID' ),
'type' => 'integer',
),
),
'provides' => array(
'group_members' => array(
'label' => 'List of group members',
'type' => 'list',
),
),
),
);
}
/**
*
*/
function mymodule_get_og_members( $nid )
{
$node = node_load( $nid );
$uids = og_get_group_members_properties( $node, array(), 'members__' . OG_STATE_ACTIVE, 'node' );
$members = user_load_multiple( $uids );
// user_load_multiple indexes by UID which might be confusing the Rules loop. Reindex!
$members = array_values( $members );
dpm( $members ); // This works!
return $members;
}
In Rules UI I've added this custom action followed by a loop. The loop suggests the provided members-list variable to iterate over and everything looks fine, yet when the Rule is run I get errors like this:
Unable to get variable group_members, it is not defined.
Unable to evaluate loop.
I've asked an overlapping question here: https://www.drupal.org/node/905632#comment-10893894
Similar posts that I've read:
How to loop over a list of Organic Group users using Rules