Hi,

I want to create rule that will allow adding multiple content to selected group audience.
Basically I have content type that is "Group content" and I want to set group audience to large number of nodes via VBO.
I figure out that I should use Rules Components, but I'm not sure what data types should I use (maybe Node and List of oG membership items?) and what actions should I use, maybe "add entity to a group"?

Could you please give me some tips?

Thanks

CommentFileSizeAuthor
#2 1.png53.83 KBrolkos
#2 2.png22.31 KBrolkos
#2 3-loop.png27.43 KBrolkos
#2 4-loop-inside.png30.5 KBrolkos
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Rosamunda’s picture

Have you solved this?

rolkos’s picture

FileSize
30.5 KB
27.43 KB
22.31 KB
53.83 KB

Yes, it's not most elegant way. In Rules Component:

Variables: Node, List of node items as parameter

Condition: Enity has field > og_group_ref
Action: Loop > paremeter: list of node items
in loop action "Add entity to group", Data selector "node" (parameter), Group data selectro Group id-list.

Then I added this action to my node list view (vbo), and I paste grops nid as a argument, it would be better to have some nice widget, but run this only once so I used view to list nid that are groups.

Exported component:

{ "rules_admin_set_content_group_audience" : {
    "LABEL" : "Admin Set Content Group Audience",
    "PLUGIN" : "rule",
    "REQUIRES" : [ "rules", "og" ],
    "USES VARIABLES" : {
      "content" : { "label" : "Content", "type" : "node" },
      "group_ids" : { "label" : "Groups IDs", "type" : "list\u003Cnode\u003E" }
    },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "content" ], "field" : "og_group_ref" } }
    ],
    "DO" : [
      { "LOOP" : {
          "USING" : { "list" : [ "group-ids" ] },
          "ITEM" : { "group_id_list_element" : "Group ID element" },
          "DO" : [
            { "og_group_content_add" : { "entity" : [ "content" ], "group" : [ "group-id-list-element" ] } }
          ]
        }
      }
    ]
  }
}
Rosamunda’s picture

Status: Active » Closed (fixed)

THANK YOU VERY MUCH FOR SHARING YOUR SOLUTION!!!
Really appreciate it!

Yuri’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

adding the group ID manually isn't really a solution, more like a workaround.
Still looking for a proper way to accomplish this.

Miranda_NS’s picture

I'm with that. I've tried to show the VBO on the group page and pass the Nid into the VBO to automatically assign selected content to the group. Can't figure out how to do it...

Yuri’s picture

@miranda_ns As a workaround using VBO, I used a patch that fetches a views argument as an 'integer' parameter in rules. In that way you can create a views argument for current group from context the usual way, and set the argument in VBO settings.
In that way you can create vbo views of content and bulk add them to the current group thats in the group context, even on group content pages.
However, still a workaround. Current issue 'Add entity to group' is not working for me like it should.
What I did is instead of using 'add entity to group', just use rules to copy paste the field value of the current node from url (and make sure the view is in a group content node of course)

See https://drupal.org/node/1967702