Is there a way in Rules to Flag a user with multiple flags all at once? For example fetching a list of all Flags based on a Flag property, and then setting all of the flags in this list to "Flagged" for the specific user?
Yes there a way in Rules to Flag a user with multiple flags all at once (as in your question), and maybe even by some kind of fetching as you described. However, you can for sure use the Conditional Rules module to flag a user with multiple flags all at once. Here is a sample rule to illustrate how such rule would look like:
{ "rules_flag_a_user_with_multiple_flags" : {
"LABEL" : "Flag a user with multiple flags",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules_conditional", "flag" ],
"ON" : { "flag_flagged_superuser" : [] },
"DO" : [
{ "CONDITIONAL" : [
{
"IF" : { "NOT flag_flagged_user" : {
"flag" : "follow",
"user" : [ "flagged-user" ],
"flagging_user" : [ "flagging_user" ]
}
},
"DO" : [
{ "flag_flaguser" : {
"flag" : "follow",
"user" : [ "flagged-user" ],
"flagging_user" : [ "flagging_user" ],
"permission_check" : "1"
}
}
]
},
{
"ELSE IF" : { "NOT flag_flagged_user" : {
"flag" : "friend",
"user" : [ "flagged-user" ],
"flagging_user" : [ "flagging_user" ]
}
},
"DO" : [
{ "flag_flaguser" : {
"flag" : "friend",
"user" : [ "flagged-user" ],
"flagging_user" : [ "flagging_user" ],
"permission_check" : "1"
}
}
]
}
]
}
]
}
}
Some details about the above rule, which uses flags with machine names superuser
, follow
and friend
:
- Rules Event: A user has been flagged, as "superuser".
- Rules Actions:
- If the flagged user is NOT flagged with flag "follow", by the flagging user, Then flag the flagged user, with flag "follow", by the flagging user.
- If the flagged user is NOT flagged with flag "friend", by the flagging user, Then flag the flagged user, with flag "friend", by the flagging user.
If you adapt the machine names of the flags to fit your own flag names, you should be able to import it in your own site (provided the Conditional Rules module is enabled also).
So with that, a user that gets flagged with superuser
, and which is not yet flagged with follow
, will also be flagged with follow
. And the similar for the friend
flag.
BTW, even though this answer is about entities of type "user", you can use a similar technique for any entity.
Easy, no?
PS: I'm assuming this question is about D7 ...