Warning: Undefined array key "#options" leads to TypeError: Drupal\Core\Form\OptGroup::flattenOptions():

Created on 22 December 2023, 11 months ago
Updated 8 April 2024, 8 months ago

Problem/Motivation

In cases where the options are empty, the following error is displayed:

TypeError: Drupal\Core\Form\OptGroup::flattenOptions(): Argument #1 ($array) must be of type array, null given, called in /var/www/docroot/modules/contrib/webform/src/Plugin/WebformElement/OptionsBase.php on line 222 in Drupal\Core\Form\OptGroup::flattenOptions() (line 23 of core/lib/Drupal/Core/Form/OptGroup.php).

Steps to reproduce

In my case, I'm using the Webform remote fields β†’ module.

  • Install Drupal 10.2.0
  • Install Webform Remote Fields @2.0.0-alpha2
  • Enable the webform_remote_fields_examples Module
  • Go to "/admin/structure/webform". You will see 4 example forms
  • Go to "/form/remote-example", Select a user and select an option, then submit the form.
  • After this, go to the form results, and try to edit them. You'll see the error.

Proposed resolution

  • Ensure the value exists
  • Cover all cases on webform/src/Plugin/WebformElement/OptionsBase.php
  • Use null coalescing for better standardization

This issue is similar to the issue https://www.drupal.org/project/webform/issues/3324914 β†’ , but the delivered solution does not cover all field types that has ['#option']. It missed checkboxes and radios.

Remaining tasks

  • Create tests

User interface changes

- None

API changes

- None

Data model changes

- None

πŸ› Bug report
Status

Closed: won't fix

Version

6.2

Component

Code

Created by

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

Comments & Activities

Production build 0.71.5 2024