Hi there,

first of all, I'm very impressed with what you have done here so far! I have just started to play around with the module, trying to evaluate the use for an upcoming project.

Is there anyway of bulk-assigning existing content to groups? I have a large set of preexisting content that I would need to assign to a main group. I'm aware that I could do this programmatically, but I thought to ask first if anyone has already done this and can point me to a simple way of doing this.

Best regards and keep up the good work here!

Comments

kristiaanvandeneynde’s picture

Hi there, I'm glad you like the module!
I think you can solve your problem in two ways with Rules and Views Bulk Operations.

Example 1

  1. Create a Rules component with just an action set
  2. Accept a Node and a Group parameter
  3. Set a data value: [node:group], [group]
  4. Save entity: [node]
  5. Configure a VBO to use this component and provide the nodes through a view
  6. Let the user manually input a group id on the VBO screen

Example 2

  1. Create a Rules component with just an action set
  2. Accept a Node parameter
  3. Create a fixed Group variable [group] (by entering an id in the free input)
  4. Set a data value: [node:group], [group]
  5. Save entity: [node]
  6. Configure a VBO to use this component and provide the nodes through a view
berliner’s picture

Status: Active » Fixed

Thanks for your response. I appreciate your help.
Rules is out of the question though, I'm looking for a simple way. And rules is not simple ;)

I'll go with a coded solution then.

kristiaanvandeneynde’s picture

You're welcome.

I would recommend looking into Rules and VBO though, they can be powerful tools in your toolbox once mastered. That being said, I think the learning curve for Rules is very low compared to Panels or Views for example.

Good luck with development!

berliner’s picture

The problem ist not that Rules is not powerful enough or too difficult to learn. But I'd rather cut my arm than using it in a production website for a customer. It's just a little too complex and I don't like having too much business logic in the database.
VBO is great, but I wouldn't install these modules just for a one time data setup.

Thanks anyways.

MrPeanut’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev
Status: Fixed » Active

I am attempting both solutions from #1 and am getting the following error:

Recoverable fatal error: Argument 2 passed to group_access() must be an instance of Group, null given, called in /drup/sites/all/modules/group/group.entity.inc on line 219 and defined in group_access() (line 24 of /drup/sites/all/modules/group/helpers/group.inc).

My action set is pretty simple — accepts a node parameter, set a data value (node:group set to 1) and save entity node.

The view is just a table with two fields (bulk operations and nid).

kristiaanvandeneynde’s picture

You cannot set [node:group] directly to an integer with Rules if I'm not mistaken. It requires you to provide a Group entity. See my previous answer: "Create a fixed Group variable [group] (by entering an id in the free input)".

Pierre.Vriens’s picture

kristiaanvandeneynde’s picture

Closing as fixed due to lack of activity.

kristiaanvandeneynde’s picture

Status: Active » Fixed
Rustan’s picture

Status: Fixed » Active

I do not understand how to do "6: Let the user manually input a group id on the VBO screen" from example 1 in #1, I guess this is what causes this error.

I am getting the same error as #5. Here is the export of the rule for Example 1 in #1:

{ "rules_assign_group_to_content" : {
    "LABEL" : "Assign group to content",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "TAGS" : [ "groups", "vbo" ],
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : {
      "node" : { "label" : "Node", "type" : "node" },
      "group" : { "label" : "Group", "type" : "group" }
    },
    "ACTION SET" : [
      { "data_set" : { "data" : [ "node:group" ], "value" : [ "group" ] } },
      { "entity_save" : { "data" : [ "node" ], "immediate" : "1" } }
    ],
    "PROVIDES VARIABLES" : [ "group" ]
  }
}

When I do execute with it from rules it works fine. But when I add it to a VBO I get the error message.

Rustan’s picture

kristiaanvandeneynde

You cannot set [node:group] directly to an integer with Rules if I'm not mistaken. It requires you to provide a Group entity. See my previous answer: "Create a fixed Group variable [group] (by entering an id in the free input)".

It works to do this with execute in rules, seems likely it should be possible to do from VBO as well.

Testing example 2 in #1 works when doing execute in Rules, but gives the error message (in the log) when calling from VBO and not displaying as a VBO:

Recoverable fatal error: Argument 2 passed to group_access() must be an instance of Group, null given, called in /usr/share/nginx/html/sites/all/modules/contrib/group/group.entity.inc on line 215 and defined in group_access() (line 24 of /usr/share/nginx/html/sites/all/modules/contrib/group/helpers/group.inc).

The automatic form that should be displayed in VBO to create the input is not shown, due to something in Group breaking.

I tried creating a very simple rules component that only takes nodes from VBO, then calling another component that assigns content to a fixed group. This fails with the same error in the log as above.

This is the error message that Views shows when auto-updating, that causes the error in the log above:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /admin/structure/views/view/vbo_assign/preview/page_1/ajax
StatusText: Service unavailable (with message)
ResponseText: 

I am very confused on what to do. Can someone provide a sample export component?

kristiaanvandeneynde’s picture

I'm moving this to the top of my list, will try to investigate this when I have some more time.

kristiaanvandeneynde’s picture

Status: Active » Fixed

I've found the "bug".

You need to make sure the component exposes access, i.e.: uses permissions. Otherwise Rules will check for access on everything that your rule component is trying to manipulate. It will as such try to check 'view' access on [node:group], which is obviously empty as the rule doesn't know yet which node or group it will be using.

Checking for access on an empty entity will result in a crash in Group's case, because it did not properly implement entity_access(). Entity API can actually check for access against a NULL entity, which translates to: "Check for access against all entities."

One could argue that Rules is at fault here because it incorrectly calls entity_access(). It may not intend to ask for access to all entities, but because it checks access for a NULL entity it actually does. Pushing a fix that will avoid future crashes like this and marking this as fixed.

You can use the example rule below and it works perfectly with VBO. Pay extra attention to the "ACCESS_EXPOSED" : "1", part, which is the checkbox under the components Settings fieldset.

{ "rules_assign_a_node_to_a_group" : {
    "LABEL" : "Assign a node to a group",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ACCESS_EXPOSED" : "1",
    "USES VARIABLES" : {
      "node" : { "label" : "Node", "type" : "node" },
      "group" : { "label" : "Group", "type" : "group" }
    },
    "ACTION SET" : [ { "data_set" : { "data" : [ "node:group" ], "value" : [ "group" ] } } ]
  }
}

Rustan’s picture

Awesome, thanks! Works perfectly.

I added a howto on this to the documentation.

Pierre.Vriens’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Joel MMCC’s picture

I applied the patch given in #2317195-55: Allow more than one parent by node / subgroup successfully, but it now seems to have broken this issue!

The Rules Component that this issue told me to import worked fine before the patch, but now fails integrity check. When attempting to execute the VBO, I get this in an error box near the top:

The utilized component rules_assign_a_node_to_a_group fails the integrity check.

When attempting to edit the Component, I see this in red underneath it in the Components listing, and again in the list of Action Sets when I try to Edit the Component:

Error: The data type of the configured argument does not match the parameter's value requirement.

And finally, when I try to Edit the Action Set, I see this above the Data Selectors collapsed fieldset:

Data types: Select data of the type List of group items.

Am I correct in assuming that the original field type for the “node:group” was simply “Group item” as opposed to “List of group items” and that this change is what enabled multiple parent groups per node? If so, how do I go about getting a Rules Component to provide a list of Groups to assign Nodes to?

I also note that there are “Data selectors” with names like “node:group:0:” through “node:group:3:” (note colon at end in both) in addition to “node:group” and that all five of those have the Label “Parent Groups” and Description “The group(s) the node belongs to.” Are those then individual Integer-type entries to allow individually setting the first, second, third, and fourth (0–3) Parents? Does this mean that that patch still limits Nodes to belonging to a maximum of four Groups each?

(The Rules Edit Action Set “Data selectors” really needs to add a column for “Data Type” so that we can see which selectors are which types, but that’s a Feature Request for another Module.)

Joel MMCC’s picture

Solved it. Must install March 8, 2017 7.x-1.x-dev release (or stable once one exists — would presumably be 7.x-1.9 or later) of Entity API. The current stable 7.x-1.8 has a bug that breaks this.

More details and an altered Rules Component here: #2885077-2: AJAX error on Rules Action “Add Item to List” (to assign Node to Group) if non-Gnode BEFORE executing, with #2317195 Multiple Parent Groups patch applied.
Main difference is in the "ACTION SET" which must be:

"ACTION SET" : [
      { "list_add" : { "list" : [ "node:group" ], "item" : [ "group" ], "unique" : "1" } }

instead of:
"ACTION SET" : [ { "data_set" : { "data" : [ "node:group" ], "value" : [ "group" ] } } ]

Joel MMCC’s picture

I’ve verified that Entity API v1.9 stable version incorporates the needed patch. No need to use -dev anymore.

Deno’s picture

Has anyone tried this in D8?

I tried to design a simple table that would allow me to do some bulk operations (like set status of boolean field for many nodes at once) on group nodes & relationships, but VBO doesn't even show this kind of options. I know it did in D7. :-(

To make it worse, D8 Rules is still in alfa, currently alfa 4. I tried the Alfa 3 release and it was completely broken for me.

docsaj’s picture

Request to all expert users of group module. If there is a working solution for this issue then please make a youtube video on that. I really badly need this feature.

Moreover, if there is a way to change the group of a node created in one group to transfer it to another group then please share that method too.

Joel MMCC’s picture

@docsaj #22, are you using D7 with the #2317195: Allow more than one parent by node / subgroup patch? If so, see my #19, which references this: #2885077-2: AJAX error on Rules Action “Add Item to List” (to assign Node to Group) if non-Gnode BEFORE executing, with #2317195 Multiple Parent Groups patch applied.. That’s an Issue I created about an error that was occurring if you tried to use Rules to Add Nodes to a Group. It turned out to be caused by a bug in Entity API, which has since been patched, and the patch then rerolled into a -dev and now into the stable version as of version 7.x-1.9 (the current stable 7.x release as of this writing). Provided you have either that -dev or 7.x-1.9 or later, that error will no longer occur.

If you have that version or later and the latest versions of Rules and Views and Views Bulk Objects (VBO) installed, the Rule I posted in there should work fine. Simply select-and-copy the exported Rule code, then on your Site Admin do a Configuration ⇒ Rules ⇒ Components ⇒ Import Component and paste the copied code in there, then proceed with the import. A new VBO Action Component will appear: “Assign a node to a group.”

If you just want the code and don’t want to have to read the other Issue, here it is:

{ "rules_assign_a_node_to_a_group" : {
    "LABEL" : "Assign a node to a group",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ACCESS_EXPOSED" : "1",
    "USES VARIABLES" : {
      "node" : { "label" : "Node to assign", "type" : "node" },
      "group" : { "label" : "Group to assign Node to", "type" : "group" }
    },
    "ACTION SET" : [
      { "list_add" : { "list" : [ "node:group" ], "item" : [ "group" ], "unique" : "1" } }
    ]
  }
}

If you’re not using the #2317195: Allow more than one parent by node / subgroup patch, then use the code provided in this issue’s #13 instead. That’s for the standard version of Groups 7.x which allows nodes to only belong to a single parent group at a time.

In either case, you can then proceed as usual to create or edit a VBO View with “Add a node to a group” selected as one of the available VBO Actions.