Field referencing group roles throws an error

Created on 22 April 2019, over 5 years ago
Updated 3 March 2023, almost 2 years ago

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.

🐛 Bug report
Status

RTBC

Version

3.0

Component

Code

Created by

🇦🇹Austria jordik

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom very_random_man

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

  • Status changed to Needs work almost 2 years ago
  • 🇧🇪Belgium lobsterr

    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.

  • Status changed to Needs review almost 2 years ago
  • 🇧🇪Belgium lobsterr

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

  • Status changed to RTBC almost 2 years ago
  • 🇬🇧United Kingdom very_random_man

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

Production build 0.71.5 2024