Problem with Drupal 9 compatibility

Thanks for creating this module! It looks great though we have some issues with it. :-)

The module doesn't work as it is now with Drupal 9.

Trying to add an user to the group produces the following error:

messageNotice: Undefined index: handler_settings in Drupal\group_roles_management\Plugin\EntityReferenceSelection\GroupTypeRoleSelection->buildEntityQuery() (line 28 of modules/contrib/group_roles_management/src/Plugin/EntityReferenceSelection/GroupTypeRoleSelection.php).

You can fix this by changing the following:
$group_type_id = $this->configuration['handler_settings']['group_type_id'];
to:
$group_type_id = $this->configuration['group_type_id'];

But fixing that, another error pops up:

Error: Call to a member function getTranslationFromContext() on null in Drupal\group_roles_management\Plugin\EntityReferenceSelection\GroupTypeRoleSelection->getReferenceableEntities() (line 76 of modules/contrib/group_roles_management/src/Plugin/EntityReferenceSelection/GroupTypeRoleSelection.php).

And even after fixing that, there are issues with setting the roles.

If you get the correct role listing to display in the group member edit screen, there will be an issue with the following workflow:
- Create a group with two roles "Editor" and "Admin"
- Allow Editor role to manage the Editor-role but not Admin
- Now edit an user who has the Admin role (you won't see the user having an admin role) and hit save
- That user now doesn't have the Admin-role anymore because the save just stored the values in the form.

Problem with existing groups

After enabling this module, you can edit the role permissions for existing groups but these aren't stored in the correct format in the backend somehow. So you see your role based permissions in the Group Type Permissions screen but whenever you call functions like $group->hasPermission("manage members with role {$role_id}", $account) they will always return false for existing groups.

If you add a new group, there are no issues with this.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

j-vee created an issue. See original summary.

j-vee’s picture

Issue summary: View changes
lobsterr’s picture

Assigned: Unassigned » lobsterr

lobsterr’s picture

Assigned: lobsterr » Unassigned
Status: Active » Needs review

@j-vee
Please review a PR
1) Fixed "messageNotice: Undefined index: handler_settings in "
2) Fixed "Error: Call to a member function getTranslationFromContext() on null in "
3) Fixed the bug, when we have user with multiple roles. Now we keep all the roles to which a user doesn't have access
4) The last issue "Problem with existing groups". Unfortunately, I can't reproduce. Are you sure you set correctly rights and you check the correct role.

j-vee’s picture

Status: Needs review » Reviewed & tested by the community

And I can't reproduce my second issue anymore. Fixing these issues seems to have remedied that problem as well so in my books, this is all good!

j-vee’s picture

Status: Reviewed & tested by the community » Needs work

Sorry, I spoke too soon!

Continuing on with my other dev work with this update installed, I ran into the following issue when I tried to add a Node to a Group:

Notice: Trying to get property 'group_roles' of non-object in group_roles_management_group_content_presave() (line 65 of modules/contrib/group_roles_management/group_roles_management.module).
Warning: Invalid argument supplied for foreach() in group_roles_management_group_content_presave() (line 65 of modules/contrib/group_roles_management/group_roles_management.module).
Warning: Invalid argument supplied for foreach() in group_roles_management_group_content_presave() (line 68 of modules/contrib/group_roles_management/group_roles_management.module).

And trying to add a new group brings about this error:
Drupal\Core\Entity\EntityStorageException: Field group_roles is unknown. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 810 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Any ideas?

lobsterr’s picture

What a rookie mistake. My bad. I will fix it soon

lobsterr’s picture

Status: Needs work » Needs review

It should be fixed

j-vee’s picture

Status: Needs review » Reviewed & tested by the community

Can't find any errors with the latest code :-) Thanks for your quick reaction, works really well!

  • LOBsTerr committed 7dedfad on 1.0.x
    Issue #3181094 by LOBsTerr, j-vee: Drupal 9 compatibility issues...
lobsterr’s picture

Status: Reviewed & tested by the community » Fixed

@J-vee Thanks for your help

  • LOBsTerr committed 54eac11 on 3181094-drupal-9-compatibility
    Issue #3181094: Drupal 9 compatibility issues...
  • LOBsTerr committed d135a37 on 3181094-drupal-9-compatibility
    Merge branch 'group_roles' into '3181094-drupal-9-compatibility'
    
    Issue...
  • LOBsTerr committed d777b31 on 3181094-drupal-9-compatibility
    Issue #3181094: Aplly logic only for group membership content.
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.