How to add selected users to OG Group from field selection when creating group
-
02-01-2021 - |
Domanda
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?
Soluzione
This is the rule I created to solved it:
- After updating/adding existing content of type
- Entity has field Parameter: Entity: [node], Field: FIELD WITH UNAMES
- Crete a LOOP
- (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" ] } }
]
}
}
]
}
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a drupal.stackexchange