4

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)

8
  • Are you trying to do that via a custom module or via the og_module itself ?
    – mchar
    Jul 4, 2016 at 18:13
  • Sorry, via rules. I see I tagged it with rules but in the actual question it wasn't explicitly stated. Jul 4, 2016 at 18:25
  • Are you aware of the (fixed) OG issue drupal.org/node/1327326 ? If so, what's the difference of your question with that issue? Jul 4, 2016 at 19:53
  • That issue only relates to my issue as it is the action I am using. However, the problem is that in rules the Group role is not brought into scope for me to use that action upon it. Even after adding conditions, "entity has field" or other actions, such as "fetch entity by id". I shouldn;t even have to add the conditions as I am working directly on the membership entity where the property exists. Jul 4, 2016 at 20:20
  • Merci, with your extra comment your actual question is much clearer (at least to me). I need "some" time now to do some special rules / og experiments (ping me via an extra comment if it takes too long) ... Jul 5, 2016 at 7:51

1 Answer 1

3
+100

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" } }
        }
      }
    ]
  }
}
1
  • Thanks. I will give this a try. The reason I am not using "User has become a group member" is because the user has already become a member. I am looking to make modifications to the membership when it is updated based on conditions of values in other field. The membership also acts as a profile of their membership in a group and can have a different profile per group. Jul 6, 2016 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.