TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback

Created on 20 November 2022, over 1 year ago
Updated 18 June 2024, 8 days ago

After migration to group version 2

We can not add entity(contente plugins installed)

TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, class "Drupal\group\Entity\GroupContent" not found in call_user_func() (line 398 of core/lib/Drupal/Core/Field/FieldConfigBase.php).

Stops with a WSOD.

🐛 Bug report
Status

RTBC

Version

2.2

Component

Code

Created by

🇩🇪Germany bennos

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.

  • 🇪🇸Spain aleix

    Setting as major because it breaks existing sites using defined groups coming from 1.x.

    I found the same errors when upgrading from 1.5 to 2.1, It happens when associating content to group for a group_content type configured previously.

    The culprit is residual configuration set in (for example for blog content type) : "core.base_field_override.group_content.blog-group_membership.uid" , it sets:

    status: true
    dependencies:
      config:
        - group.content_type.blog-group_membership
    id: group_content.blog-group_membership.uid
    field_name: uid
    entity_type: group_content
    bundle: blog-group_membership
    label: 'Group content creator'
    description: 'The username of the group content creator.'
    required: false
    translatable: false
    default_value: {  }
    default_value_callback: 'Drupal\group\Entity\GroupContent::getDefaultEntityOwner'
    settings:
      handler: default
      handler_settings: {  }
    field_type: entity_reference

    So when getting the callback to obtain uid in https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Field%21F... things get broken.

    The same may happen for group uid as there is this conf:

    status: true
    dependencies:
      config:
        - group.type.blog
    id: group.blog.uid
    field_name: uid
    entity_type: group
    bundle: blog
    label: 'Group creator'
    description: 'The username of the group creator.'
    required: false
    translatable: false
    default_value: {  }
    default_value_callback: 'Drupal\group\Entity\Group::getDefaultEntityOwner'
    settings:
      handler: default
      handler_settings: {  }
    field_type: entity_reference

    This was set in https://git.drupalcode.org/project/group/-/blob/8.x-1.x/group.install#L495 so I guess that this residual configuration must be removed when upgrading to group 2 or 3.

  • @aleix opened merge request.
  • Status changed to Needs review about 1 year ago
  • 🇪🇸Spain aleix

    I have tested what's done in MR, removing the config using this script with drush:
    (If anyone would test it make a backup of all items of core.base_field_override.group.*.uid, they will be removed)

    
    /**
     * @file
     */
    
    /**
     * Removes base field definitions that was set in group v1
     * to obtain the default value callback.
     */
    function group_update_9211() {
      $config_factory = \Drupal::configFactory();
      foreach ($config_factory->listAll('core.base_field_override.') as $config_name) {
        $base_field_override = $config_factory->getEditable($config_name);
    
        if ($base_field_override->get('field_name') !== 'uid') {
          continue;
        }
    
        switch ($base_field_override->get('entity_type')) {
          case 'group':
            $class = 'Drupal\group\Entity\Group';
            break;
    
          case 'group_content':
            $class = 'Drupal\group\Entity\GroupContent';
            break;
    
          default:
            continue 2;
        }
    
        if (
          $base_field_override->get('default_value_callback') === $class . '::getCurrentUserId' or
          $base_field_override->get('default_value_callback') === $class . '::getDefaultEntityOwner'
        ) {
          $base_field_override->delete();
        }
      }
    }
    
    group_update_9211();
    
  • I'm encountering the same error with group^2.1, but my Drupal version is 10.0.9. I would greatly appreciate any suggestions or guidance on how to address this situation.

  • 🇩🇪Germany dbielke1986

    We have the same on our page so we need to wait for the fix and stay with 1.5.

  • 🇩🇪Germany dbielke1986

    The reason for this is the setting "The group creator automatically becomes a member" within the group type with the issue #3364226.
    So, if you are creating a new group of this type it will try to add the user to the individual role which not exists/can not be configured.

    Next to the fix you will have two possibilities:
    1) Uncheck the "The group creator automatically becomes a member"
    2) Create a Role called "Admin" with the individual member setting

    BR

  • Status changed to RTBC 11 months ago
  • Hello all. I have just looked at the MR and tested it on our system. It works and everything looks good! Thanks!

  • Status changed to Needs work 9 months ago
  • 🇨🇭Switzerland Berdir Switzerland

    I think this should not delete the config overrides, they exist for a reason, but it should update the default value. node module has an example for this:

    
    /**
     * Updates stale references to Drupal\node\Entity\Node::getCurrentUserId.
     */
    function node_post_update_modify_base_field_author_override() {
      $uid_fields = \Drupal::entityTypeManager()
        ->getStorage('base_field_override')
        ->getQuery()
        ->condition('entity_type', 'node')
        ->condition('field_name', 'uid')
        ->condition('default_value_callback', 'Drupal\node\Entity\Node::getCurrentUserId')
        ->execute();
      foreach (BaseFieldOverride::loadMultiple($uid_fields) as $base_field_override) {
        $base_field_override->setDefaultValueCallback('Drupal\node\Entity\Node::getDefaultEntityOwner')->save();
      }
    }
    

    To cover both the classname change and the method rename, I think it's safe to just leave out the default_value_callback definition.

    I'll create a separate MR to do that change instead.

  • @berdir opened merge request.
  • Status changed to Needs review 9 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update 9 months ago
    9,628 pass
  • 🇨🇦Canada bbombachini London, ON

    We're on core 9.5.10 and using groups 2.2.0 and I've tried the patch attached but I still get the same issue when I try to save content with an image. I'm using groupmedia module, so it might be related.
    I'm wondering if we might need a similar patch on groupmedia as well.

  • 🇨🇭Switzerland Berdir Switzerland

    What's the *exact* message you get? This should fix it for all group_content bundles.

  • 🇨🇦Canada bbombachini London, ON

    This is the message I got @berdir:

    TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, class "Drupal\group\Entity\GroupContent" not found in call_user_func() (line 400 of /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Field/FieldConfigBase.php)
    
    #0 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Field/FieldConfigBase.php(400): call_user_func('Drupal\\group\\En...', Object(Drupal\group\Entity\GroupRelationship), Object(Drupal\Core\Field\Entity\BaseFieldOverride))
    #1 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Field/FieldItemList.php(169): Drupal\Core\Field\FieldConfigBase->getDefaultValue(Object(Drupal\group\Entity\GroupRelationship))
    #2 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(271): Drupal\Core\Field\FieldItemList->applyDefaultValue()
    #3 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(129): Drupal\Core\Entity\ContentEntityStorageBase->initFieldValues(Object(Drupal\group\Entity\GroupRelationship), Array)
    #4 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(94): Drupal\Core\Entity\ContentEntityStorageBase->doCreate(Array)
    #5 /Users/admin/Sites/ulocal/docroot/modules/contrib/group/src/Entity/Storage/GroupRelationshipStorage.php(156): Drupal\Core\Entity\ContentEntityStorageBase->create(Array)
    #6 /Users/admin/Sites/ulocal/docroot/modules/contrib/group/src/Entity/Group.php(145): Drupal\group\Entity\Storage\GroupRelationshipStorage->createForEntityInGroup(Object(Drupal\media\Entity\Media), Object(Drupal\group\Entity\Group), 'group_media:ima...', Array)
    #7 /Users/admin/Sites/ulocal/docroot/modules/contrib/groupmedia/src/AttachMediaToGroup.php(180): Drupal\group\Entity\Group->addRelationship(Object(Drupal\media\Entity\Media), 'group_media:image')
    #8 /Users/admin/Sites/ulocal/docroot/modules/contrib/groupmedia/src/AttachMediaToGroup.php(113): Drupal\groupmedia\AttachMediaToGroup->assignMediaToGroups(Array, Array)
    #9 /Users/admin/Sites/ulocal/docroot/modules/contrib/groupmedia/groupmedia.module(39): Drupal\groupmedia\AttachMediaToGroup->attach(Object(Drupal\group\Entity\GroupRelationship))
    #10 [internal function]: groupmedia_entity_update(Object(Drupal\group\Entity\GroupRelationship))
    #11 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(426): call_user_func_array(Object(Closure), Array)
    #12 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(405): Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object(Closure), 'groupmedia')
    #13 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(433): Drupal\Core\Extension\ModuleHandler->invokeAllWith('entity_update', Object(Closure))
    #14 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(251): Drupal\Core\Extension\ModuleHandler->invokeAll('entity_update', Array)
    #15 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(900): Drupal\Core\Entity\EntityStorageBase->invokeHook('update', Object(Drupal\group\Entity\GroupRelationship))
    #16 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(598): Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update', Object(Drupal\group\Entity\GroupRelationship))
    #17 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(781): Drupal\Core\Entity\EntityStorageBase->doPostSave(Object(Drupal\group\Entity\GroupRelationship), true)
    #18 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(523): Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object(Drupal\group\Entity\GroupRelationship), true)
    #19 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(804): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\group\Entity\GroupRelationship))
    #20 /Users/admin/Sites/ulocal/docroot/core/lib/Drupal/Core/Entity/EntityBase.php(339): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\group\Entity\GroupRelationship))
    #21 /Users/admin/Sites/ulocal/docroot/modules/contrib/entitygroupfield/src/Field/EntityGroupFieldItemList.php(65): Drupal\Core\Entity\EntityBase->save()
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update 9 months ago
    9,628 pass
  • 🇨🇭Switzerland Berdir Switzerland

    I had the wrong entity type in the query, it should work now, but you'll need to run the update again or run the code in a different way. Or manually update the config.

  • 🇨🇦Canada bbombachini London, ON

    All good, seems to be working now, thanks @berdir.

  • 🇩🇪Germany dercheffe Sersheim, Germany

    Get a same/similar error when a user wants to join into a group. Even when I apply the MR of #12 as patch.

    The website encountered an unexpected error. Please try again later.
    TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, class "Drupal\group\Entity\GroupContent" not found in call_user_func() (line 400 of core/lib/Drupal/Core/Field/FieldConfigBase.php).
    
    call_user_func('Drupal\group\Entity\GroupContent::getDefaultEntityOwner', Object, Object) (Line: 400)
    Drupal\Core\Field\FieldConfigBase->getDefaultValue(Object) (Line: 169)
    Drupal\Core\Field\FieldItemList->applyDefaultValue() (Line: 271)
    Drupal\Core\Entity\ContentEntityStorageBase->initFieldValues(Object, Array) (Line: 129)
    Drupal\Core\Entity\ContentEntityStorageBase->doCreate(Array) (Line: 94)
    Drupal\Core\Entity\ContentEntityStorageBase->create(Array) (Line: 156)
    Drupal\group\Entity\Storage\GroupRelationshipStorage->createForEntityInGroup(Object, Object, 'group_membership') (Line: 75)
    Drupal\group\Controller\GroupMembershipController->join(Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    
  • Hello @berdir , how can i apply your modification in my project? beacause i dont see any patch to apply it
    Thx

  • 🇩🇪Germany dercheffe Sersheim, Germany

    Merge request 106 worked. As Berdir wrote, it's only working, if you apply the patch before upgrading from groups V1 to V2. Perhaps it's possible to re-trigger the db actions as part of the patch again?

  • 🇨🇭Switzerland Berdir Switzerland

    My merge request is against V2, use that, not the patch.

    @drupal_developer2022, you should see various links to https://git.drupalcode.org/project/group/-/merge_requests/106 on automated comments and issue summary above. and if you then append .diff, like https://git.drupalcode.org/project/group/-/merge_requests/106.diff, then you can download and save that as a patch.

  • @berdir it works for me thanks!

  • 🇩🇪Germany dbielke1986

    Is there a chance to get this in a new, stable release for group?
    We are still on version 1.5 because of this issue.

    We need to switch because we moved to PHP8.2

  • 🇨🇦Canada plousia

    @berdir, the patch works for me and solved this issue, thanks. One thing that might help someone, the .diff file wouldn't apply, but when I went to the merge request page and downloaded the .patch file, it applied.

  • 🇨🇦Canada benoit.borrel

    For info, merge request 106 worked for me too.
    Config: Drupal 10.2.3, Group 2.2.2.

  • 🇮🇳India PratikshaD Mumbai

    hi,

    I am also facing the same issue after upgrading the group module.
    After adding the group, though, I no longer see the issue, but the created groups do not appear on the Group list page.
    Please suggest.

  • Status changed to RTBC 21 days ago
  • 🇩🇪Germany dbielke1986

    Is working for me since a few months.
    I think we can change to RTBC

  • 🇳🇱Netherlands ronaldtebrake

    Can also confirm this did the trick for us

  • 🇺🇦Ukraine Andriy Khomych

    Can confirm that it works fine, attached patch from MR 106.

Production build 0.69.0 2024