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.
Comment | File | Size | Author |
---|---|---|---|
#12 | interdiff-10-12.txt | 1.67 KB | LOBsTerr |
#12 | group3-3049971-12.patch | 3.53 KB | LOBsTerr |
#11 | interdiff-7-11.txt | 3.4 KB | LOBsTerr |
#11 | group1-3049971-11.patch | 3.38 KB | LOBsTerr |
#10 | Reference_group_roles_error-3049971-10.patch | 3.49 KB | very_random_man |
Comments
Comment #2
JordiK CreditAttribution: JordiK commentedPatch provided - please check.
Comment #3
JordiK CreditAttribution: JordiK commentedComment #4
JordiK CreditAttribution: JordiK commentedComment #5
JordiK CreditAttribution: JordiK commentedComment #6
LOBsTerr CreditAttribution: LOBsTerr at European Commission and European Union Institutions, Agencies and Bodies commentedI 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
Comment #7
LOBsTerr CreditAttribution: LOBsTerr at European Commission and European Union Institutions, Agencies and Bodies commentedIt 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
Comment #8
LOBsTerr CreditAttribution: LOBsTerr at European Commission and European Union Institutions, Agencies and Bodies commentedComment #9
JordiK CreditAttribution: JordiK commentedGreat 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.
Comment #10
very_random_man CreditAttribution: very_random_man as a volunteer commentedThe patch in #9 was no longer applying so I've adapted it to work with the new additions.
Comment #11
LOBsTerr CreditAttribution: LOBsTerr at European Commission and European Union Institutions, Agencies and Bodies commentedSo, 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.
Comment #12
LOBsTerr CreditAttribution: LOBsTerr at European Commission and European Union Institutions, Agencies and Bodies commentedI have updated the patch to use individual filter instead. It works correctly now
Comment #13
very_random_man CreditAttribution: very_random_man as a volunteer commentedI 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). :-)