list_allowed_values_setting_validate dies with PHP Fatal error on PHP 8.1

Created on 2 March 2023, almost 2 years ago
Updated 12 May 2023, over 1 year ago

Problem/Motivation

list_allowed_values_setting_validate dies with PHP Fatal error on PHP 8.1 during field creation.
TypeError: explode(): Argument #2 ($string) must be of type string, array given in explode() (line 285 of modules/field/modules/list/list.module).

Steps to reproduce

Using PHP 8.1 via Manage Field tab on a content type
Add new field List (text) field with Check boxes/radio buttons widget
Click Save

On the Field setting step set allowed values function values, keep the Allowed values list field empy
Click Save field settings

On the Edit step click Save settings

Observe error.

Proposed resolution

diff --git a/modules/field/modules/list/list.module b/modules/field/modules/list/list.module
index 47544be68..aae045823 100644
--- a/modules/field/modules/list/list.module
+++ b/modules/field/modules/list/list.module
@@ -67,7 +67,7 @@ function list_field_settings_form($field, $instance, $has_data) {
       $form['allowed_values'] = array(
         '#type' => 'textarea',
         '#title' => t('Allowed values list'),
-        '#default_value' => empty($settings['allowed_values_function']) ? list_allowed_values_string($settings['allowed_values']) : array(),
+        '#default_value' => empty($settings['allowed_values_function']) ? list_allowed_values_string($settings['allowed_values']) : '',
         '#rows' => 10,
         '#element_validate' => array('list_allowed_values_setting_validate'),
         '#field_has_data' => $has_data,

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

7.0 ⚰️

Component
Field 

Last updated 3 days ago

Created by

🇧🇾Belarus dmitrii

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

Comments & Activities

Production build 0.71.5 2024