How to flag or unflag an entity with multiple flags at once? I have a large number of user Flags created. When a user performs certain actions on the website a Rule is triggered Flagging them (based on the action) which in turn provides that user with additional access and other privileges. When the user performs an exceptional action on the website the user is Flagged with several Flags all at once, providing them with multiple privileges all at once.

The reason I am using Flags instead of Roles is because there is quite a large number of actions that can be performed on the website; and trying to manage the permissions for such a huge amount or Roles is not only unwieldy but it takes up unnecessary database space, which Flags do not.

So the question then: 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? At the moment I am setting a single Rules action for every single Flag that needs to Flag the user under certain conditions. This works but is very time consuming. If there is a better to way achieve this without Flags I am open to that as well.
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 ...