Steps to reproduce
On a content entity, add a new field of type Entity Reference -> Other...
Select for "Type of item to reference" - Configuration -> Group role.
Set allowed number of values to unlimited.
In Manage form display set the widget of the field to "Check boxes / radio buttons".

Error
When you try to edit the content entity, the following error appears:

Notice: Undefined index: group_type_id in Drupal\group\Plugin\EntityReferenceSelection\GroupTypeRoleSelection->buildEntityQuery() (line 27 of modules\contrib\group\src\Plugin\EntityReferenceSelection\GroupTypeRoleSelection.php)
The reason for this is that we are not in group context, but in node.

Furthermore, the base_plugin_label is also missing, which damages the dropdown Reference method (adds a blank line) in the field settings.
As a result, the field is not rendered.

Solution
In GroupTypeRoleSelection.php check, if we can get the group_type_id and use it.
Otherwise, list all (non-internal) roles for all group types.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JordiK created an issue. See original summary.

JordiK’s picture

Status: Active » Needs review
JordiK’s picture

Version: 8.x-1.0-rc2 » 8.x-1.3
LOBsTerr’s picture

Status: Needs review » Needs work

I have checked your patch and it solves the issue with missing "base_plugin_label", all custom EntitySelection plugins must have this property, but this error "Undefined index: group_type_id" is not solved I got "Notice: Undefined index: handler_settings". Configuration of the plugin doesn't contain this key.
I will try to check

LOBsTerr’s picture

It is a bit strange, but it looks like this Selection plugin has never been finished. We have group_type_id parameter, but we don't have any ways to set it. I have added a configuration form to set the group type based on which we want to filter roles. Plus I removed filter by inner property, because there are cases when we want references internal roles also

LOBsTerr’s picture

Status: Needs work » Needs review
JordiK’s picture

Great solution, LOBsTerr!

Since not everyone needs the internal roles shown, I added a checkbox to the plugin config "Include internal group roles" - see patch attached. It is empty by default, and will add the internal roles to the list, if checked.

IMHO it is good UX and all fields already using a reference to group roles will continue working without config updates.

very_random_man’s picture

The patch in #9 was no longer applying so I've adapted it to work with the new additions.

LOBsTerr’s picture

Status: Needs review » Needs work
FileSize
3.38 KB
3.4 KB

So, I see a confusion here.
For group 1, we have internal roles and external roles. For group 2 and 3, we have individual roles.
So, we have a mix here some code is still for group 1 and some for group 2, 3 and it is wrong.

I have updated patch for group 1 to support filter by internals roles. I will do the same for group 2 and 3.

LOBsTerr’s picture

Status: Needs work » Needs review
FileSize
3.53 KB
1.67 KB

I have updated the patch to use individual filter instead. It works correctly now

very_random_man’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm this is working for both custom group role reference fields and also on the group membership form (which the previous patch had broken). :-)