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

  1. Agree if this is the right home for this code.
  2. Reviews/refinements.
  3. RTBC.
  4. 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.

Comments

dww created an issue. See original summary.

dww’s picture

Status: Active » Needs review
StatusFileSize
new1.84 KB
dww’s picture

Issue summary: View changes

Note: 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

kristiaanvandeneynde’s picture

Status: Needs review » Needs work

This 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.

dww’s picture

Hah, 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

dww’s picture

Status: Needs work » Needs review
StatusFileSize
new1.92 KB
new1.61 KB

Like so?

kristiaanvandeneynde’s picture

+++ b/src/Plugin/GroupContentEnablerManager.php
@@ -217,6 +217,24 @@ class GroupContentEnablerManager extends DefaultPluginManager implements GroupCo
+  public function getPluginIdByEntityType($entity_type_id, $bundle) {

Would 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 :)

dww’s picture

StatusFileSize
new1.92 KB
new1.68 KB

Righto. 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? ;)

dww’s picture

Title: Add a getPluginIdByEntityType() method to src/Plugin/GroupContentEnablerManager » Add a getPluginIdsByEntityType() method to src/Plugin/GroupContentEnablerManager
Issue summary: View changes

Updating title and summary to match patch #8. ;)

kristiaanvandeneynde’s picture

Minor nitpicks.

  1. +++ b/src/Plugin/GroupContentEnablerManagerInterface.php
    @@ -102,6 +102,19 @@ interface GroupContentEnablerManagerInterface extends PluginManagerInterface, Ca
    +   * Returns the content enabler plugin IDs for a given entity type and bundle.
    

    For a given entity type.

  2. +++ b/src/Plugin/GroupContentEnablerManagerInterface.php
    @@ -102,6 +102,19 @@ interface GroupContentEnablerManagerInterface extends PluginManagerInterface, Ca
    +   *   The optional entity bundle ID.
    

    (optional) The entity bundle.

dww’s picture

Issue summary: View changes
StatusFileSize
new1.91 KB
new708 bytes

RTBC? ;) Would really love to see this in rc6 so entitygroupfield can require that.

Thanks!
-Derek

kristiaanvandeneynde’s picture

Need to make some minor changes/fixes to Group next week for the Subgroup module, will try and have a look then.

kristiaanvandeneynde’s picture

Seems 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.

dww’s picture

Cool. 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

dww’s picture

Related issues: +#3156276: InvalidQueryException when dealing with user entities
StatusFileSize
new1.91 KB
new787 bytes

I 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

kristiaanvandeneynde’s picture

Issue tags: -blocker +Group 8.1 target

This 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.

kristiaanvandeneynde’s picture

Issue tags: -Group 8.1 target +Group 8.2 target
kristiaanvandeneynde’s picture

chriscalip’s picture

@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.

$manager = $container->get('plugin.manager.group_content_enabler');
$manager->getPluginGroupContentTypeMap();
jnicola’s picture

Man 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!