Looking at the rule you included, it seems that your Rules Event is fine. But obviously your Rules Action (to send an eMail) is to only send it to 1 (hardcoded) eMail ID. Read on for more details about how you can get this to work ...
Step 1:
Create a flag (similar to yours) to flag a group. In my case I named it (surprise ...) "Flag a group", and with machine name "flag_a_group
" (just replace in what follows this machine name of that flag with your own flag's machine name).
Step 2:
Create a Rules Component "Send eMail to all members of a Group", which you can do like so:
- The type of this component is an "Action Set" (no need for any conditions).
- Action 1 is to build a list of all the members of the flagged group. It uses "Fetch entity by property", with these additional specs:
- Entity type value = Group Membership.
- Property value = Group.
- Value of the data selector = Group.
- limit result count = blank (we do not want to limit the nr of results).
- Provided variables = "Group members" (variable label) and "group_members" (variable name).
- Action 2 is to iterate (= loop) over each of the members of the flagged group. It uses "Add a (rules) loop", with these additional specs:
- The list to loop over = group-members
- Current list item = "Member of group" (variable label) and "member_of_group" (variable name).
- Sub-action (i) of this Action 2 is to just "Show a message on the site" (while QA-testing this Rules Component), with message type = Status and with a message something like "Group member named "[member-of-group:user:name]" and eMail "[member-of-group:user:mail]" will receive an eMail because of flagging this "[group:group-type]" group titled "[group:title]" and id "[group:gid]" (note the various tokens which might be interesting).
- Sub-action (ii) of this Action 2 is to actually send an eMail to the "member_of_group" being processed in the loop, using various tokens similar to those in Sub-action (i).
Here is how the Rules Component looks like (in Rules export format):
{ "rules_send_email_to_all_members_of_a_group" : {
"LABEL" : "Send eMail to all members of a Group",
"PLUGIN" : "action set",
"OWNER" : "rules",
"TAGS" : [ "group" ],
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : { "group" : { "label" : "Group", "type" : "group" } },
"ACTION SET" : [
{ "entity_query" : {
"USING" : {
"type" : "group_membership",
"property" : "group",
"value" : [ "group" ]
},
"PROVIDE" : { "entity_fetched" : { "group_members" : "Group members" } }
}
},
{ "LOOP" : {
"USING" : { "list" : [ "group-members" ] },
"ITEM" : { "member_of_group" : "Member of group" },
"DO" : [
{ "drupal_message" : { "message" : "Group member named \u0022[member-of-group:user:name]\u0022 and eMail \u0022[member-of-group:user:mail]\u0022 will receive an eMail because of flagging this \u0022[group:group-type]\u0022 group titled \u0022[group:title]\u0022 and id \u0022[group:gid]\u0022" } },
{ "mail" : {
"to" : "[member-of-group:user:mail]",
"subject" : "eMail notification to group [group:title]",
"message" : "Hello [member-of-group:user:name],\r\n\r\nyou are a member of the group [group:title] (which is of type [group:group-type]).\r\n\r\nYou are receiving this eMail since user [site:current-user] just flagged this group.\r\n\r\nGreetings,\r\n\r\nPS: contact the site admin by eMail (via [site:mail]) for more details if needed",
"language" : [ "" ]
}
}
]
}
}
]
}
}
If you have the Rules UI enabled you can simply import the above rule in your own site, no need to tweak anything in it, though you may want to tune the Subject and Message content of the actual eMail as you want (just remember the various tokens you may want to use).
Step 3:
Create a rule "Send a group notification by flagging a group", which you can do like so:
- Rules Event: When a group is flagged with the flag from Step 1.
- Rules Conditions: none (no need for it).
- Rules Action: perform the Rules Component from Step 2.
Here is how the rule looks like (in Rules export format, disabled as shown here):
{ "rules_send_a_group_notification_by_flagging_a_group" : {
"LABEL" : "Send a group notification by flagging a group",
"PLUGIN" : "reaction rule",
"ACTIVE" : false,
"OWNER" : "rules",
"REQUIRES" : [ "rules", "flag" ],
"ON" : { "flag_flagged_flag_a_group" : [] },
"DO" : [
{ "component_rules_send_email_to_all_members_of_a_group" : { "group" : [ "flagged-group" ] } }
]
}
}
If you have the Rules UI enabled you can simply import the above rule in your own site, after you adapt the flag's machine name to fit yours. Don't forget to enable the rule also.
Step 4:
Add any additional parameters to the Rules Component to pass any relevant extra data from the rule (from Step 3) to the Rules Component (from Step 2). E.g. that date field you added to the flag to be included in the email also (as in your question, like "Elle commencera [flagging:field-flag-date:value] et se terminera [flagging:field-flag-date:value2].".
For more details about this, refer to the answer to "How to pass a Flag field's value to a Rules Component triggered by the flag?". Some more details about how to use that answer in the context of this question also:
- looking at the message of the eMail in your rule here, I see 2 tokens that look like dates:
[flagging:field-flag-date:value]
and [flagging:field-flag-date:value2]
. But your screenprints do not show how this "field-flag-date
" is defined.
- My best guess is that you have 1 field with 2 values, no?. If so, you only need 1 Rules Condition to check "Entity has field", which I think will be "
flagging:field_flag_date
". And in the Rules Action you should then be able to specify (drill down) to both [flagging:field-flag-date:value]
and [flagging:field-flag-date:value2]
.
Voilà
So here you go: only 3 (robust) modules (Flag, Rules and Group) is what's needed to be able to trigger an eMail of all members of a Group that is flagged by an authorized user (with zero custom code).
True, the actual eMail is hardcoded in the Rules Component (would be nice to transform that into something with 2 extra Flag "fields", to specify during the flagging what the actual Subject and message content of the eMail should be).
VBO alternative
Another solution could be to use a combination of Rules and VBO. That would have the advantage that you get all the power of Views available to filter which group members you want to be eMailed ...