Warning: foreach() argument must be of type array|object, null given i GroupRoleStorage.php

Created on 17 October 2023, about 1 year ago
Updated 30 May 2024, 7 months ago

Problem/Motivation

I've created a Test group, but after creation, it's not there (/admin/group). It reads: There are no groups yet.

Steps to reproduce

Create a Test group. It's fairly new installation. I'm using it with field_group module.
Check stack trace for more details.
Possibly related: #2908729: PHP Warning from loadByUserAndGroup for member without roles

Details

Status message
Membership Test has been created.
Error message
Warning: foreach() argument must be of type array|object, null given in Drupal\group\Entity\Storage\GroupRoleStorage->loadByUserAndGroup() (line 114 of modules/contrib/group/src/Entity/Storage/GroupRoleStorage.php).
Drupal\group\Entity\Storage\GroupRoleStorage->loadByUserAndGroup(Object, Object, ) (Line: 19)
Drupal\group\Entity\GroupMembership->getRoles() (Line: 90)
Drupal\group\GroupMembership->getRoles() (Line: 62)
Drupal\group\Access\IndividualGroupPermissionCalculator->calculatePermissions(Object, 'individual') (Line: 138)
Drupal\flexible_permissions\ChainPermissionCalculator->calculatePermissions(Object, 'individual') (Line: 41)
Drupal\group\Access\GroupPermissionCalculator->calculateFullPermissions(Object) (Line: 46)
Drupal\group\Access\GroupPermissionChecker->hasPermissionInGroup('administer members', Object, Object) (Line: 213)
Drupal\group\Entity\Group->hasPermission('administer members', Object) (Line: 71)
Drupal\group\Access\GroupAccessResult::allowedIfHasGroupPermissions(Object, Object, Array, 'OR') (Line: 103)
Drupal\group\Plugin\Group\RelationHandlerDefault\AccessControl->relationshipAccess(Object, 'view', Object, 1) (Line: 84)
Drupal\group\Plugin\Group\RelationHandler\GroupMembershipAccessControl->relationshipAccess(Object, 'view', Object, 1) (Line: 51)
Drupal\group\Entity\Access\GroupRelationshipAccessControlHandler->checkAccess(Object, 'view', Object) (Line: 105)
Drupal\Core\Entity\EntityAccessControlHandler->access(Object, 'view', Object, ) (Line: 710)
Drupal\Core\Entity\ContentEntityBase->access('view') (Line: 118)
Drupal\group\Entity\Form\GroupRelationshipForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 592)
🐛 Bug report
Status

Needs work

Version

3.3

Component

Code

Created by

🇬🇧United Kingdom kenorb

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

Comments & Activities

  • Issue created by @kenorb
  • Assigned to Shreya_98
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    9,628 pass
  • @shreya_th opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India Shreya_98

    Hi @kenorb,
    I have fixed this issue i.e. " Warning: foreach() argument must be of type array|object " and also created MR for this. Kindly review the changes.

    Thank you.

  • 🇺🇸United States rishi kulshreshtha

    I have attached a backport patch for the 1.x version.

  • Status changed to Needs work 10 months ago
  • 🇧🇪Belgium kristiaanvandeneynde Antwerp, Belgium

    What version are you on? When I look at the code I see this is already fixed.

          // Get the IDs from the 'group_roles' field, without loading the roles.
          if ($membership = $this->groupMembershipLoader->load($group, $account)) {
            foreach ($membership->getGroupRelationship()->group_roles as $group_role_ref) {
              $ids[] = $group_role_ref->target_id;
            }
          }
    

    The MR does nothing but make the above more verbose.

  • 🇺🇸United States wylbur Minneapolis, Minnesota, USA

    I found this issue from a google search for the error message. My issue persisted, even after applying the patch. Since I was testing patches, I started over with a fresh install on a clean D10 site. No issues after the fresh install.

    I received that error after trying to create new groups. The install process never completed after each group install. Each time I ran the install, it would return to the group page, with no installs, and the same number of error messages for each attempt I had made. It seemed clear that the system was creating groups, but hanging on each install. Each of these hung installs created another entity that caused an error. In my case the patch never resolved the issue or suppressed the errors.

    Not a solution, but hope this helps someone else trying to diagnose this.

Production build 0.71.5 2024