Problem/Motivation
After installing the module. I set up a group type with two fields. When saving it I get the "Attempt to create a field without a field_name" error (https://www.drupal.org/project/group/issues/3391452). It does create the group type. When I try and create a group, I get this error:
InvalidArgumentException: Field group_roles is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 616 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Drupal\Core\Entity\ContentEntityBase->get() (Line: 91)
Drupal\group\Entity\Storage\GroupRoleStorage->loadByUserAndGroup() (Line: 41)
Drupal\group\Entity\GroupMembership->getRoles() (Line: 90)
Drupal\group\GroupMembership->getRoles() (Line: 64)
Drupal\group\Access\IndividualGroupPermissionCalculator->calculatePermissions() (Line: 138)
Drupal\flexible_permissions\ChainPermissionCalculator->calculatePermissions() (Line: 41)
Drupal\group\Access\GroupPermissionCalculator->calculateFullPermissions() (Line: 40)
Drupal\group\QueryAccess\GroupQueryAlter->doAlter() (Line: 143)I am unable to use the module as this error seems unavoidable.
Solution
This issue occurs when group relationship types are created during config sync. The group_roles field is required for all group_membership relationship types. When a new relationship type is created, GroupRelationshipType::postSave() runs post-install tasks including GroupMembershipPostInstall::installGroupRolesField() to create the bundle-specific field config. However, this method intentionally skips field creation when \Drupal::isConfigSyncing() returns TRUE (see line 43 of GroupMembershipPostInstall.php) to avoid creating config objects during import. This assumes the field configs will be included in the imported configuration, but if relationship types are created during config sync without corresponding field configs in the import, the fields are never created. The merge request adds update hook group_update_11402() that scans all existing group_membership relationship types and creates any missing group_roles field configurations.
Issue fork group-3505906
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
Comment #2
jeffmattsonComment #3
jeffmattsonComment #4
jeffmattsonComment #5
kristiaanvandeneyndeCan you provide steps to reproduce on a clean install?
Comment #6
jeffmattsonI had installed the module using composer and then enabled this module using config. This doesn't run the install hook so the module was not installed correctly.
The solution was this:
1. Installed the module with composer.
2. In the UI or using Drush enabled the module.
3. Exported the configs.
4. Module works as expected after site creation and config import.
5. Profit.
This is something that people may not know about Drupal. I sure didn't.
Comment #7
jeffmattsonComment #8
kristiaanvandeneyndeThanks for updating the issue with your findings. Not everyone does that so I really appreciate it.
Comment #9
barbarae commented3 months to figure out this issue:
Here is the solution we used:
This worked!
so, replace "administrators" with your role machine name and run the script. It creates the missing group_roles . Only do this if you are actually missing the group_roles.
The need for this fix was due to a botched hook update execution along the way somewhere , or botched upgrade. We ran this script to avoid having to re-install from scratch. Now the
/admin/grouproute loads without crashing although we did have to reload our opcache (apcu) and rebuild drupal cache also.The groups module could ideally supply a hook_update to check for missing group_roles and add them if missing.
Comment #10
barbarae commentedIdeally the hook_update would handle sanity checks and ensure the expected group_roles exist.
Comment #11
vlyalko commentedI am having the same issue with the upgrade of the group module to 3.3.5 version.
On the first load of the site i got the error for the flexible_permissions discussed here https://www.drupal.org/project/group/issues/3484817.
Cleared cache and was able to get to the login screen. After login in, I am getting the same error from this issue. Tried to do what was recommended in #6, but i am getting warning that 'field_config' entity with ID 'group_relationship.ahrc_pl_hrc_g_3-group_membership.group_roles' already exists.'
drush updb -y -> no pending updates
Trying to clear cache multiple times. Still the same error.
Comment #12
ben.hamelinThanks @barbarae for comment in #9. I ran into this today and that helped guide me to a solution. Below is an update hook I worked on locally to help get past this. But before sharing that, I think this is at least partially related to proper configuration around group roles. This was a clean install of Groups 3.3.5, not an upgrade. This is a new build. I had created a new group type and enabled gnode to support the content type relation for managing access to that type. I then ran into this error when trying to create a new Group of that type. What I think was wrong was that I had not defined any group admin roles for this group type.
Comment #13
jeffmattsonComment #15
jeffmattsonComment #16
kristiaanvandeneyndeThere was a bug where a module install could trigger the creation of a group_roles field instance before the storage was there. This was fixed in #3611557: Figure out which core update broke Group2to3UpdateTest.
From the IS:
That is the issue at hand, people were using incomplete exports. So while I appreciate the OP adding an MR here, this issue is a support request and will not see any code committed under that status.
It seems the answer has been provided already, so will close as fixed. I strongly suggest people who suffer from the IS run the code here once, but then remove it and reset the update hook count to what it's supposed to be.