Question

I have an OG and a field that lists users with checkboxes. Is there a way using Rules, to add the selected users as group members when group is saved/updated?

Was it helpful?

Solution

This is the rule I created to solved it:

  1. After updating/adding existing content of type
  2. Entity has field Parameter: Entity: [node], Field: FIELD WITH UNAMES
  3. Crete a LOOP
  4. (In Loop) Subscribe user to group -- Parameter: User: [list-item], Group: [site:og-context--node]

Here is an export of my rule:

{ "rules_watch_list_group_add" : {
  "LABEL" : "Watch List Group Add",
  "PLUGIN" : "reaction rule",
  "OWNER" : "rules",
  "REQUIRES" : [ "rules", "og" ]
  "ON" : { "node_insert" : [], "node_update" : [] },
  "IF" : [
    { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_watch_list" } }
  ],
  "DO" : [
    { "LOOP" : {
        "USING" : { "list" : [ "node:field-watch-list" ] },
        "ITEM" : { "list_item" : "Current list item" },
        "DO" : [
          { "og_subcribe_user" : { "user" : [ "list-item" ], "group" : [ "site:og-context--node" ] } }
          ]
        }
      }
    ]
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top