TypeError: Drupal\Core\Field\WidgetBase::setWidgetState(): Argument #4 ($field_state) must be of type array, null given

Created on 15 March 2023, over 1 year ago
Updated 17 March 2023, over 1 year ago

Problem/Motivation

Our site uses Paragraphs and Conditional Fields. When saving a conditional field condition where the control field is a paragraph field, I receive the following error:

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

TypeError: Drupal\Core\Field\WidgetBase::setWidgetState(): Argument #4 ($field_state) must be of type array, null given, called in /var/www/html/modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php on line 2252 in Drupal\Core\Field\WidgetBase::setWidgetState() (line 497 of core/lib/Drupal/Core/Field/WidgetBase.php).
Drupal\paragraphs\Plugin\Field\FieldWidget\ParagraphsWidget->multipleElementValidate(Array, Object, Array)
call_user_func_array(Array, Array) (Line: 282)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'conditional_field_edit_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('conditional_field_edit_form', Array, Object) (Line: 591)
Drupal\Core\Form\FormBuilder->processForm('conditional_field_edit_form', Array, Object) (Line: 323)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, 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: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
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: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 686)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I don't know if this counts as a bug, or a support request, so I've categorized it as a bug for now. However, I was able to identify where the issue occurs in the code and create a patch that fixes the error and maintains the ability to save changes as expected.

Steps to reproduce

  1. Install Paragraphs (8.x-1.15) and Conditional Fields (4.0.0-alpha2) on a Drupal site running core version 9.5.4 or 10.0.4 (version numbers current as of the date of this issue's submission).
  2. Go to a content type and create a condition where the control field is a paragraphs field.
  3. Click "Add dependency".
  4. On the next page, click "Save settings" (it doesn't seem to matter what option(s) you choose on this step.
  5. The site will crash with the error noted above.

Proposed resolution

I'll attach the patch I made to this issue.

πŸ› Bug report
Status

Active

Version

1.15

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jsutta United States

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

Comments & Activities

  • Issue created by @jsutta
  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    Patch attached.

  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    Uploading a new version of the patch that adds a check of the $widget_state variable to InlineParagraphsWidget.php's multipleElementValidate() function. The check must now validate before the rest of the function can execute.

Production build 0.71.5 2024