I created a new content type and activated the group content plugin for it in the group types.
Creating the content gives no problems, but when it is opened again for editing and saved, it shows

The website encountered an unexpected error. Please try again later.

As far as I see from the error log, it says the group reference for the node is empty? But that is not the case, editing the content keeps its group field just the way it is with a group selected.

TypeError: Argument 4 passed to Drupal\social_group\SetGroupsForNodeService::setGroupsForNode() must be of the type array, null given, called in /data/disk/o1/static/opensoc3/html/profiles/contrib/social/modules/social_features/social_group/social_group.module on line 1342 in Drupal\social_group\SetGroupsForNodeService->setGroupsForNode() (line 51 of /data/disk/o1/static/opensoc3/html/profiles/contrib/social/modules/social_features/social_group/src/SetGroupsForNodeService.php) #0 /data/disk/o1/static/opensoc3/html/profiles/contrib/social/modules/social_features/social_group/social_group.module(1342): Drupal\social_group\SetGroupsForNodeService->setGroupsForNode(Object(Drupal\node\Entity\Node), Array, Array, NULL, false) #1 [internal function]: social_group_save_group_from_node(Array, Object(Drupal\Core\Form\FormState)) #2 /data/disk/o1/static/opensoc3/html/core/lib/Drupal/Core/Form/FormSubmitter.php(111): call_user_func_array('social_group_sa...', Array) #3 /data/disk/o1/static/opensoc3/html/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState)) #4 /data/disk/o1/static/opensoc3/html/core/lib/Drupal/Core/Form/FormBuilder.php(589): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState)) #5 /data/disk/o1/static/opensoc3/html/core/lib/Drupal/Core/Form/FormBuilder.php(318): Drupal\Core\Form\FormBuilder->processForm('node_question_e...', Array, Object(Drupal\Core\Form\FormState)) #6 /data/disk/o1/static/opensoc3/html/core/lib/Drupal/Core/Controller/FormController.php(93): Drupal\Core\Form\FormBuilder->buildForm('node_question_e...', Object(Drupal\Core\Form\FormState)) #7 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #8 /data/disk/o1/static/opensoc3/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #9 /data/disk/o1/static/opensoc3/html/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #10 /data/disk/o1/static/opensoc3/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #11 /data/disk/o1/static/opensoc3/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #12 /data/disk/o1/static/opensoc3/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #13 /data/disk/o1/static/opensoc3/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #14 /data/disk/o1/static/opensoc3/html/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #15 /data/disk/o1/static/opensoc3/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #16 /data/disk/o1/static/opensoc3/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #17 /data/disk/o1/static/opensoc3/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #18 /data/disk/o1/static/opensoc3/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #19 /data/disk/o1/static/opensoc3/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #20 /data/disk/o1/static/opensoc3/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #21 /data/disk/o1/static/opensoc3/html/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #22 /data/disk/o1/static/opensoc3/html/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #23 {main}.

Comments

Yuri created an issue. See original summary.

Yuri’s picture

Issue summary: View changes
Yuri’s picture

Shortly after this, I can't access the sites dblog any more /admin/reports/dblog
it gives the same error The website encountered an unexpected error. Please try again later
It appears that watchdog does not catch some faulty code https://www.drupal.org/node/1279680#comment-8899497
However the actual faulty code is causing it, therefore an opensocial issue

Yuri’s picture

Priority: Normal » Major
Yuri’s picture

Reinstalling Open Social solved this

Yuri’s picture

Priority: Major » Normal
Status: Active » Closed (works as designed)
jcmartinez’s picture

Version: 8.x-5.x-dev » 8.x-7.0
Status: Closed (works as designed) » Active

I'm reopening because this issue persists and nuking a site and reinstalling Open Social, as suggested, isn't always an option.

In my case, I'm using the "Social Flexible Group" and I created a new content type for which I have activated the group content plugin in the group types, as described originally on this issue above.

When I edit a node of my new content type, I get the same error reported above:

The website encountered an unexpected error. Please try again later.
TypeError: Argument 4 passed to Drupal\social_group\SetGroupsForNodeService::setGroupsForNode() must be of the type array, null given, called in /app/html/profiles/contrib/social/modules/social_features/social_group/social_group.module on line 1542 in Drupal\social_group\SetGroupsForNodeService->setGroupsForNode() (line 52 of profiles/contrib/social/modules/social_features/social_group/src/SetGroupsForNodeService.php).

After inspecting line 1542 and testing different cases, I believe the error comes from the assumption that there is a #default_value that might not be there for custom content types.

$original_groups = $form['groups']['widget']['#default_value'];

When the value isn't there things start to fails after this code runs.

jcmartinez’s picture

I have created a pull request at GitHub with code that solves this issue: https://github.com/goalgorilla/open_social/pull/1584

You can add this patch to your code inside the "extra" block of the composer.json at the root of your site:

    "patches": {
      "goalgorilla/open_social": {
                "Issue# 3035308 - Fix fatal error when editing content with a custom content type": "https://github.com/goalgorilla/open_social/pull/1584.patch"
            }
    },
    "enable-patching": true

Then run: composer update goalgorilla/open_social

garchris’s picture

Was having a similar issue and #8 seems to resolve that particular issue; but it produced a different problem: Group referenced from content is not saved. Error report shows the following:
Warning: array_filter() expects parameter 1 to be array, null given in social_group_secret_form_node_form_alter() (line 196 of /var/www/html/linkup/html/profiles/contrib/social/modules/social_features/social_group/modules/social_group_secret/social_group_secret.module)...

Drupal Version: 8.7.11
INSTALLATION PROFILE: Social (social-8.x-7.2)
Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.2.25

A note on the original issue: The fatal error only occurs when one of the autocomplete widgets is used on the group reference field. Select list or Check box widgets do not produce this problem.

ronaldtebrake’s picture

Status: Active » Reviewed & tested by the community

Have rebased the patch, it's RTBC'ed
https://github.com/goalgorilla/open_social/pull/1584

Thanks for the contribution!!

Other issues mentioned in here seem to not be related to this piece of code/issue at least. Feel free to open up a different one if that doesn't already exist and we can go from there.

ronaldtebrake’s picture

Status: Reviewed & tested by the community » Fixed

will be in 7.6 and 8.3 as well, thanks!!

  • ronaldtebrake committed ca8bce6 on 8.x-7.x
    Issue #3035308 by jcmartinez: Fix fatal error when editing custom...

  • ronaldtebrake committed ac83771 on 8.x-8.x
    Issue #3035308 by jcmartinez: Fix fatal error when editing custom...

  • ronaldtebrake authored 2f060c2 on 8.x-9.x
    Merge pull request #1816 from goalgorilla/bugfix/3035308-fatal-error-...
  • ronaldtebrake committed c002b6a on 8.x-9.x
    Issue #3035308 by jcmartinez: Fix fatal error when editing custom...

Status: Fixed » Closed (fixed)

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