Problem/Motivation
The entitygroupfield module (formerly "gcontent_field" from #2813405: Add a field to view and edit content's groups) needs to be able to find the right group content enabler plugin IDs for a given entity type + bundle.
Since this seems like something potentially useful to other Group-related modules, let's add it to Group core instead of doing our own thing in entitygroupfield.
Proposed resolution
Add a getPluginIdsByEntityType() method to the src/Plugin/GroupContentEnablerManagerInterface.php and the src/Plugin/GroupContentEnablerManager.php service ('plugin.manager.group_content_enabler').
Remaining tasks
Agree if this is the right home for this code.Reviews/refinements.- RTBC.
- Commit.
User interface changes
N/A
API changes
Adds a new getPluginIdsByEntityType() method to the src/Plugin/GroupContentEnablerManagerInterface.php and the src/Plugin/GroupContentEnablerManager.php service ('plugin.manager.group_content_enabler').
Data model changes
N/A
Release notes snippet
TBD, probably not.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 3152324.11_15.interdiff.txt | 787 bytes | dww |
| #15 | 3152324-15.patch | 1.91 KB | dww |
Comments
Comment #2
dwwComment #3
dwwNote: I added the 'blocker' tag since we either need this to land here, or we need to do our own thing, before entitygroupfield will work.
Brief local testing and the pseudo field is working fine with this patch applied to Group core.
Curious to hear what @kristiaanvandeneynde thinks about this. ;)
Thanks!
-Derek
Comment #4
kristiaanvandeneyndeThis assumes there can only be one plugin for a given entity type (and bundle), which is not the case. It's perfectly valid for 2 plugins to serve the same entity type, but it would get weird if both had entity_access set to TRUE.
You could have GroupMembership alongside GroupMemberInvite for instance, where both add users to groups without adding any entity access.
Comment #5
dwwHah, good point. ;) The gcontent_field widget was written to assume only 1. Yikes. Now your feedback at #2813405-210: Add a field to view and edit content's groups (which I moved to #3152724: Improve architecture per kristiaanvandeneynde) is making more sense. Ugh.
I was hoping not to have to completely rewrite all that, get an initial release (even if only an alpha) out, and then iterate from there. But it sounds like #3152724 might be a more critical blocker to getting that module working in general. It certainly works now in a more "normal" / simple setup, but it's not really going to work for everyone.
Clearly you're not going to add this method as-is. Would you be willing to commit this if it returned an array of plugin IDs? We could land such a method before RC6, and then at least the API wouldn't have to change. Dealing with multiple values in the array becomes entitygroupfield's problem.
Thoughts?
Thanks!
-Derek
Comment #6
dwwLike so?
Comment #7
kristiaanvandeneyndeWould have to be getPluginIdsByEntityType and $bundle would have to be optional. It would suck to have to provide a bundle for entity types that have none. And even if the entity type has bundles, the plugin could choose to ignore them (you don't have to specify a bundle in your plugin and then it would work on all bundles).
That said, I'm not entirely opposed to adding this to the base module. It's the fact that this would be the first of its kind that has me hesitating. I'd hate for the manager to become bloated with these types of getters over time, even though I can't think of a better place to put them than the manager.
I'm in the process of reducing the obscene amount of bloat in the plugins, so I'm not keen on adding bloat elsewhere without giving it some thought first :)
Comment #8
dwwRighto. Optional makes sense. The prior code already seemed to handle the case where a plugin doesn't care about bundles, but this is indeed cleaner.
Totally hear you about giving this some thought first! ;) Much appreciated and highly welcome. I wouldn't want to add bloat, either, and I definitely wouldn't want to add broken bloat.
How's this? ;)
Comment #9
dwwUpdating title and summary to match patch #8. ;)
Comment #10
kristiaanvandeneyndeMinor nitpicks.
For a given entity type.
(optional) The entity bundle.
Comment #11
dwwRTBC? ;) Would really love to see this in rc6 so entitygroupfield can require that.
Thanks!
-Derek
Comment #12
kristiaanvandeneyndeNeed to make some minor changes/fixes to Group next week for the Subgroup module, will try and have a look then.
Comment #13
kristiaanvandeneyndeSeems like I had a similar idea over at #3134072: Implement the query access handling for grouped entities, so depending on how that goes, I might commit this at the same time.
Comment #14
dwwCool. I ended up committing a work-around in entitygroupfield for now. But it'd still be nice to land this and then I can rip-out the work-around once there's an official release to depend on, instead. ;)
Thanks,
-Derek
Comment #15
dwwI put a copy of this directly into entitygroupfield so we have something while the dust settles in here. I found a bug over there dealing with user entities:
#3156276: InvalidQueryException when dealing with user entities
Whoops. New patch for here. Do you want some test coverage of this change? If so, any recommendation / preference on where it should live?
Thanks!
-Derek
Comment #16
kristiaanvandeneyndeThis should be perfectly unit-testable, so maybe GroupContentEnablerManagerTest?
That said, the patch looks good, but because of the complex if-statement we might want to test all possible scenario's so nothing breaks if some patch in the future changes the statement ever so slightly.
Given how you could work around it for now, it's no longer a blocker and I'm targeting it for the next release.
Comment #17
kristiaanvandeneyndeComment #18
kristiaanvandeneyndeCross-posting here: #2907838-21: Adding members to group in bulk
Comment #19
chriscalip commented@dww
+1 For routine that does: Given entity_type & bundle return group_content plugin_id.
As in:
id: group_content_type_00cd4145804c3
content_plugin: 'group_node:xxx'
used by group_content_field_data.type
Request withdrawn.
For anyone dealing with issue of trying to triangulate group_content plugin given entity_type and bundle.
Comment #20
jnicola commentedMan would this be useful right about now... i'd even accept something at returns an array of plugins as I could reliably just grab the first!