Problem/Motivation

We have a field "Group" in the entities that can be not a part of any group. This causes a fatal error if we visit the entity add/edit page. The error is raised in the file: modules/social_features/social_group/src/Plugin/EntityReferenceSelection/SocialGroupSelection.php

Error message:

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

Drupal\Core\Database\InvalidQueryException: Query condition 'groups_field_data.type IN ()' cannot be empty. in Drupal\Core\Database\Query\Condition->condition() (line 105 of core/lib/Drupal/Core/Database/Query/Condition.php).
Drupal\Core\Database\Query\Select->condition('groups_field_data.type', Array, 'IN') (Line: 61)
Drupal\Core\Entity\Query\Sql\Condition->compile(Object) (Line: 172)
Drupal\Core\Entity\Query\Sql\Query->compile() (Line: 80)
Drupal\Core\Entity\Query\Sql\Query->execute() (Line: 350)
Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection->getReferenceableEntities() (Line: 601)
Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem->getSettableOptions(Object) (Line: 116)
Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase->getOptions(Object) (Line: 34)
Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget->formElement(Object, 0, Array, Array, Object) (Line: 344)
Drupal\Core\Field\WidgetBase->formSingleElement(Object, 0, Array, Array, Object) (Line: 94)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 178)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 125)
Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 127)
Drupal\node\NodeForm->form(Array, Object) (Line: 149)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 532)
Drupal\Core\Form\FormBuilder->retrieveForm('node_course_quiz_form', Object) (Line: 278)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 91)
Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
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: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
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: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

Visit any entity (probably node) which is not a part of any group.

Proposed resolution

Add additional checking to prevent query to an empty array.

CommentFileSizeAuthor
#5 Clipboard01.jpg18.23 KBslowflyer

Comments

vnech created an issue. See original summary.

vnech’s picture

Title: Fatal error in "social_group/src/Plugin/EntityReferenceSelection/SocialGroupSelection.php » Fatal error in "social_group/src/Plugin/EntityReferenceSelection/SocialGroupSelection.php"
vnech’s picture

Related changes in the PR

vnech’s picture

Status: Active » Needs review
slowflyer’s picture

StatusFileSize
new18.23 KB

The patch solves the issue, but adds an empty group select on nodes with no group settings:
group select

ribel’s picture

Status: Needs review » Reviewed & tested by the community

It looks all is fixed and work as expected now in the PR.

ribel’s picture

PR was merged and will be included in the releases 10.0.6 and 10.1

  • ribel committed e510941 on 10.0.x
    Issue #3203202 by vnech: Fix fatal error in SocialGroupSelection (#2257...
navneet0693’s picture

Status: Reviewed & tested by the community » Fixed

  • 17b0d39 committed on 10.1.x
    Issue #3203202 by vnech: Fix fatal error in SocialGroupSelection (#2257...

Status: Fixed » Closed (fixed)

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