TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 349 of /Drupal/Core/Datetime/Element/Datelist.php)

Created on 15 November 2024, about 1 month ago

Problem/Motivation

I get this error when submitting a billing profile with a date field, using select list to pick a date.

Steps to reproduce

Use a date field in a billing profile in Drupal Commerce, choose to create a new payment method using this billing profile, and try to complete the checkout process.

Proposed resolution

The error occurs when the $input argument is empty in the function DateList::checkEmptyInputs($input, $parts). The value of $input can be NULL, which causes the error.
This can be fixed by the following change in line 349 from:
$filtered_input = array_filter($input, 'strlen');
to:
$filtered_input = array_filter($input ?? [], 'strlen');
The function expects $input to be an array, which is apparently not always the case. For example, $input can be explicitly set to NULL during form building in FormBuilder::handleInputElement().

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

10.3

Component

datetime.module

Created by

🇳🇱Netherlands inascon

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024