I've been breaking my head over this, searched the net with no avail.

I want to add members to a group based on a view like the default People view by selecting them and performing an action e.g. 'Add selected members to group x'.

I've created a duplicate of the people view, added a relation to group content, displayed the fields I find relevant, and so far, that's working fine. Then comes the tricky part, how to create the action with Rules and get it in the list of the VBO field.

I've tried to create a Rules component with the action Create Group content, but I don't find the correct value to enter in Group content type field. I always get a message saying it can't find the plugin... Even when, and I'm pretty sure this is the plugin I need, I fill in the group_membership group content type. I get this:

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "entity:group_content:group_membership" plugin does not exist. in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 52 of core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).

Now I'm no dev, and I can barely call myself a experienced site-builder, so If someone would have a working example, that would be great.

Issue fork group-2907838

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Tw3aky created an issue. See original summary.

thomasmurphy’s picture

The best activity related to this seems to be at https://www.drupal.org/project/group/issues/2865642 although that's related to content rather than membership.

thomasmurphy’s picture

Category: Support request » Feature request
thomasmurphy’s picture

StatusFileSize
new4.39 KB
thomasmurphy’s picture

Component: Documentation » Code
Assigned: Unassigned » thomasmurphy
Status: Active » Needs review

This is how we fixed this on one of our projects. We added a VBO action so users could be selected by exposed filters and/or checkboxes, and then added to the group selected via an autocomplete form.

This solution would obviously require installing VBO, but the plugins are stable and inactive without that module.

thomasmurphy’s picture

Version: 8.x-1.0-rc1 » 8.x-1.x-dev
heddn’s picture

Status: Needs review » Needs work
StatusFileSize
new2.23 KB

Here's some clean-up by removing the entity autocomplete and adding some more permissions checks. It also supports adding to multiple groups. Still needs to add a snowflaked SelectionPlugin for groups to filter group autocomplete by the user's access to add members to those groups. But this gets things started.

heddn’s picture

Status: Needs work » Needs review
StatusFileSize
new6.63 KB
new4.88 KB

This adds the selection plugin to filter by admin members permission.

catch’s picture

Status: Needs review » Reviewed & tested by the community

Looks like useful functionality and the patch seems fine, tested this manually and it's working well.

dbielke1986’s picture

Is there a way to implement an "Unsubscribe from Group" also?
It would be fine to have a way to remove users from (a) selected group(s) via VBO.

Thank you so much!

kristiaanvandeneynde’s picture

Will look into this for 1.1, not committing new features any more, just bugfixes.

dan_metille’s picture

+1 for committing. I'm running the latest dev and getting the following error when proceeding:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /en/batch?id=3015&op=do_nojs&op=do
StatusText: 500 Service unavailable (with message)
ResponseText: The website encountered an unexpected error. Please try again later.

With in log:

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 150 of .../web/core/lib/Drupal/Core/Entity/EntityTypeManager.php).

Any idea what can be wrong?

johnpitcairn’s picture

@sahaj: most likely a VBO issue, exposed by the query changes in Group 1.x. See #3161707: hook_query_TAG_alter does not handle empty MetaData, and the related VBO issue, for which I have proposed a patch in the VBO issue queue at #3163912: VBO does not preserve query metadata added by other modules.

dan_metille’s picture

Thanks a lot @john-pitcairn for the tips and for the patch, they did the job!

thomasmurphy’s picture

Can we get this committed?

kristiaanvandeneynde’s picture

Issue tags: +Group 8.4 target

Next release, I hope. Trying to get a release out today and a bit scared to add new stuff right before it. Will try to review this for the next release, but time is very limited nowadays.

johnpitcairn’s picture

Just a thought here, but what if there are extra required fields on the group_user entity?

kristiaanvandeneynde’s picture

Re #17 good call! That's why I had to write that awful 2-step wizard for adding content to groups in the first place.

johnpitcairn’s picture

@kristiaanvandeneynde: I'm currently attempting to refactor @Fonant's Group VBO sandbox to handle any group content entity (including users/members).

Some of the code I'm borrowing from the Entity Group Field module. I feel some of this code would be more usefully abstracted into a new or existing group service, to allow easier discovery of things like:

  • which content plugins support a specific entity type and bundle
  • which groups a specific user could add a specific entity type or specific entity to
  • which groups or group types have a specific plugin installed
  • which group types have extra and/or required fields

Any appetite for that?

In the case where entities selected for the bulk operation would need extra required fields on the group content entity to be completed, I think I'll just skip those entities, with an appropriate message at completion. There's no other good way to deal with that in a VBO context, right? Even if the view row entities are all the same bundle, I can't assume the required field values should all be the same.

johnpitcairn’s picture

See this patch against @Fonant's Group VBO sandbox module, that provides an add/remove group VBO (not core) action for any supported entity (including users/members), and useful supporting functionality in a shared base class.

kristiaanvandeneynde’s picture

Any appetite for that?

Sure, we'd just need to organize it properly instead of creating one huge monolithic helper class.

Which content plugins support a specific entity type and bundle

We should perhaps start thinking of a helper class that takes the plugin manager as a dependency and move all of these conditional getters there. Then again, the plugin manager is not the wrong place to put these.

Which groups a specific user could add a specific entity type or specific entity to

That's something we could determine by launching a query that checks for the create group content permission.

Which groups or group types have a specific plugin installed

Query for group content types by plugin ID, then ask for their group type IDs. I think we already do that in ::getPluginGroupContentTypeMap().

Which group types have extra and/or required fields

I can't imagine core not having a system for this. At least, I hope it does.

In the case where entities selected for the bulk operation would need extra required fields on the group content entity to be completed, I think I'll just skip those entities, with an appropriate message at completion. There's no other good way to deal with that in a VBO context, right?

Right, unless you can also set those fields in the bulk operation.

Even if the view row entities are all the same bundle, I can't assume the required field values should all be the same.

Depends, what if I want to mass update the roles field so all imported users have a specific role? Or taxonomy term, or whatever... :)

kristiaanvandeneynde’s picture

Status: Reviewed & tested by the community » Needs work

Needs work as per #17. We need a solution for required fields.

johnpitcairn’s picture

This particular action does at least operate on an entity that has no bundles, so at present it's handled by a single group content plugin instance, right? That might allow the form from the wizard to be pulled in as an optional user-configuration step.

What should happen if (when) there are other plugins that support the user-member relationship, and those have extra fields? Would there need to be a selection option for which plugin should be used, pulling in the relevant form via ajax or an extra step?

Do core actions support this sort of thing, or would that need to depend on VBO?

johnpitcairn’s picture

Depends, what if I want to mass update the roles field so all imported users have a specific role? Or taxonomy term, or whatever... :)

There's a module for that (maybe). This seems like a good candidate for a view based on the group_content entity itself, then VBO and Views bulk Edit might be able to update or add field values on the selected group_content entities.

thomasmurphy’s picture

I don't think #17 is a blocker. If you have additional required fields on a membership type, this would necessarily preclude a bulk action, only because the bulk action would have no basis for assuming what the default values should be. It's unreasonable to expect that bulk actions could occur in those circumstances. The original supplied patch was written to support bulk (1000+) enrolling in courses, and it works fine when circumstances allow, such as that.

aaronbauman’s picture

Patch #8 works for me

wmfinnegan’s picture

Is anyone using group roles? It would be really useful to also have a VBO action to assign a group role to group members...

dan_metille’s picture

Patch #8 does not apply any more to the last dev version

petednz’s picture

@thomasmurphy - hi Tom. Hope you're doing well. Should i expect your patch to still work as is on the latest VBO?

thomasmurphy’s picture

@petednz not sure, I'll run a test and re-upload if there's an obvious bug.

petednz’s picture

That would be great thanks @thomasmurphy

jan-e’s picture

It still works! With Drupal 9.3.11

sivakarthik229’s picture

Hi All,

There is a D9 module which I have ported from D8 and it was working fine for assigning a group role to a user for multiple groups at a time using bulk action.

https://www.drupal.org/project/group_bulk_operations

I have added a new feature request as patch which can remove a user from multiple groups using the same bulk action.

Issue: https://www.drupal.org/project/group_bulk_operations/issues/3276167

Please review and post your suggestions to make the module for better usage.

Thanks
Siva

mxh’s picture

You may also have a look whether the Group Actions module works for you.

aytee’s picture

FYI: This patch no longer works with Views Bulk Operations as of VBO 4.2.1 using Group 1.5. It will require modification. Posting this in case anybody else comes by.

pixiekat’s picture

Back when I used Organic Groups, I loved the OG Mass Add companion module (https://www.drupal.org/project/og_massadd), which allowed group admins to bulk add users to groups but also create accounts for them if they didn't exist. It would be nice to implement some of those features into Group.

nielsonm made their first commit to this issue’s fork.

graber’s picture

StatusFileSize
new2.94 KB

Here's a working VBO action, there are still a few things to improve but I think it's a good starting point.

mxh’s picture

I'm also open for improving Group Actions module in case you think there's something missing. For example, the autocomplete input is not in there, but could be added. Feel free to open an issue and ideally with a merge request there.

graber’s picture

I wasn't aware it exists, cool, I'll add a link to the VBO project page :)

mxh’s picture

Great :) I guess the module is missing a bit of good UX. But there should be ways to make it easier.

nielsonm’s picture

abramm’s picture

StatusFileSize
new6.64 KB
new967 bytes

The #8 patch no longer works with VBO 4.4.x due to signature changes.
Attaching the updated patch.