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.
| Comment | File | Size | Author |
|---|---|---|---|
| #45 | interdiff_8-45.txt | 967 bytes | abramm |
| #45 | 2907838-45.patch | 6.64 KB | abramm |
| #40 | AddUsersToGroup.php_.txt | 2.94 KB | graber |
| #8 | interdiff_7-8.txt | 4.88 KB | heddn |
| #8 | 2907838-8.patch | 6.63 KB | heddn |
Issue fork group-2907838
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
Comment #2
thomasmurphy commentedThe 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.
Comment #3
thomasmurphy commentedComment #4
thomasmurphy commentedComment #5
thomasmurphy commentedThis 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.
Comment #6
thomasmurphy commentedComment #7
heddnHere'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.
Comment #8
heddnThis adds the selection plugin to filter by admin members permission.
Comment #9
catchLooks like useful functionality and the patch seems fine, tested this manually and it's working well.
Comment #10
dbielke1986 commentedIs 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!
Comment #11
kristiaanvandeneyndeWill look into this for 1.1, not committing new features any more, just bugfixes.
Comment #12
dan_metille commented+1 for committing. I'm running the latest dev and getting the following error when proceeding:
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?
Comment #13
johnpitcairn commented@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.
Comment #14
dan_metille commentedThanks a lot @john-pitcairn for the tips and for the patch, they did the job!
Comment #15
thomasmurphy commentedCan we get this committed?
Comment #16
kristiaanvandeneyndeNext 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.
Comment #17
johnpitcairn commentedJust a thought here, but what if there are extra required fields on the group_user entity?
Comment #18
kristiaanvandeneyndeRe #17 good call! That's why I had to write that awful 2-step wizard for adding content to groups in the first place.
Comment #19
johnpitcairn commented@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:
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.
Comment #20
johnpitcairn commentedSee 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.
Comment #21
kristiaanvandeneyndeSure, we'd just need to organize it properly instead of creating one huge monolithic helper class.
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.
That's something we could determine by launching a query that checks for the create group content permission.
Query for group content types by plugin ID, then ask for their group type IDs. I think we already do that in ::getPluginGroupContentTypeMap().
I can't imagine core not having a system for this. At least, I hope it does.
Right, unless you can also set those fields in the bulk operation.
Depends, what if I want to mass update the roles field so all imported users have a specific role? Or taxonomy term, or whatever... :)
Comment #22
kristiaanvandeneyndeNeeds work as per #17. We need a solution for required fields.
Comment #23
johnpitcairn commentedThis 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?
Comment #24
johnpitcairn commentedThere'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.
Comment #25
thomasmurphy commentedI 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.
Comment #26
aaronbaumanPatch #8 works for me
Comment #27
wmfinnegan commentedIs anyone using group roles? It would be really useful to also have a VBO action to assign a group role to group members...
Comment #28
dan_metille commentedPatch #8 does not apply any more to the last dev version
Comment #29
petednz commented@thomasmurphy - hi Tom. Hope you're doing well. Should i expect your patch to still work as is on the latest VBO?
Comment #30
thomasmurphy commented@petednz not sure, I'll run a test and re-upload if there's an obvious bug.
Comment #31
petednz commentedThat would be great thanks @thomasmurphy
Comment #32
jan-e commentedIt still works! With Drupal 9.3.11
Comment #33
sivakarthik229 commentedHi 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
Comment #34
mxh commentedYou may also have a look whether the Group Actions module works for you.
Comment #35
aytee commentedFYI: 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.
Comment #36
pixiekatBack 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.
Comment #40
graber commentedHere's a working VBO action, there are still a few things to improve but I think it's a good starting point.
Comment #41
mxh commentedI'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.
Comment #42
graber commentedI wasn't aware it exists, cool, I'll add a link to the VBO project page :)
Comment #43
mxh commentedGreat :) I guess the module is missing a bit of good UX. But there should be ways to make it easier.
Comment #44
nielsonm commentedComment #45
abrammThe #8 patch no longer works with VBO 4.4.x due to signature changes.
Attaching the updated patch.