Question

Using Rules, I am trying to set a users group role anytime a new membership entity is updated, however it appears roles are not brought into scope for me to set data value nor "grant og role"

All I want is

Event: After updating an existing og membership

Action: Grant OG role: Licensee (or set data value role: Licensee or whatever og centric things it asks for)

Was it helpful?

Solution

You should note that group role is not a field or property in the og_membership entity. The og_membership entity contains the properties etid, entity_type, group_type, and gid. There are other properties, but those are the ones you are interested in. When a user is added to a group, the entity_type is user and the etid is the user id. When node content is added to a group, the entity_type is node and the etid is the node id. The og_membership entries are not updated very often, so I'm not sure why using the event "User has become a group member" isn't sufficient. Assuming you really do want to change a users group role when the og_membership is updated, then you need to verify via rule conditions that the og_membership group type is node and the og_membership entity_type is user. Then you can use the Grant OG Role action. The rule export would look something like this:

{ "rules_205092" : {
    "LABEL" : "205092",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "og" ],
    "ON" : { "og_membership_update" : [] },
    "IF" : [
      { "entity_is_of_type" : { "entity" : [ "og-membership:group" ], "type" : "node" } },
      { "entity_is_of_type" : { "entity" : [ "og-membership:entity" ], "type" : "user" } }
    ],
    "DO" : [
      { "og_grant_og_role" : {
          "account" : [ "og-membership:entity" ],
          "group" : [ "og-membership:group" ],
          "roles" : { "value" : { "licensee" : "licensee" } }
        }
      }
    ]
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top