Error: Call to a member function label() on null in Drupal\group\Entity\Controller\GroupListBuilder->buildRow() (line 131 of modules/contrib/group/src/Entity/Controller/GroupListBuilder.php).

Created on 9 March 2022, over 2 years ago
Updated 10 May 2024, about 2 months ago

Problem/Motivation

I'm using Drupal 9.3.7 and Group 8.x-1.4.
When I clicked on Group > List (admin/group), I got error:

Error: Call to a member function label() on null in Drupal\group\Entity\Controller\GroupListBuilder->buildRow() (line 131 of modules/contrib/group/src/Entity/Controller/GroupListBuilder.php).

Steps to reproduce

I had added new groups and assigned members to them through GraphQL API mutation.
I removed some groups.
I guess after that I might have faced this issue, but could not say exactly it was the culprit.

Proposed resolution

I looked into the error file "modules/contrib/group/src/Entity/Controller/GroupListBuilder.php" of line 131.

$row['type'] = $entity->getGroupType()->label();

The above code was not returning an expected value.

Then I added the following condition:
$row['type'] = ($entity->getGroupType() instanceof EntityInterface) ? $entity->getGroupType()->label() : '';

After that, the above error was resolved. But saw another error :

Error: Call to a member function shouldCreateNewRevision() on null in Drupal\group\Entity\Controller\GroupListBuilder->getDefaultOperations() (line 181 of modules/contrib/group/src/Entity/Controller/GroupListBuilder.php).

To fix this issue, I modified the existing code as below:

  $shouldCreateNewRevision = ($entity->getGroupType() instanceof RevisionableEntityBundleInterface) ? $entity->getGroupType()->shouldCreateNewRevision() : false;
    if ($shouldCreateNewRevision) {
      if ($entity->hasPermission('view group revisions', $this->currentUser)) {
        $operations['revisions'] = [
          'title' => $this->t('Revisions'),
          'weight' => 20,
          'url' => $entity->toUrl('version-history'),
        ];
      }
    }

Added a new variable $shouldCreateNewRevision and checked whether the $entity->getGroupType() is the instance o Entity Bundle Interface.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

RTBC

Version

2.2

Component

Code

Created by

🇺🇸United States npcoder

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.

Production build 0.69.0 2024