Problem/Motivation

Upgrade to 11.4.1 from 11.3.12 caused DrupalDateTime::createFromArray to wrongly generate error in custom module code.

string elements in the date array can no longer be interpreted as numbers if they have leading zero.

Steps to reproduce

executing $oDate = Drupal\Core\Datetime\DrupalDateTime::createFromArray(['year' => "2026", 'month' => "06", 'day' => "03"]);
produces error message "The array contains invalid values."

The workaround in the module is to specifically cast the fields as (int).

Proposed resolution

Revert the error detection code to as it was before 11.4, or specifically allow for leading zero in the supplied data.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

cadencia created an issue. See original summary.

quietone’s picture

Title: Change of validation in date array wrongly causes error » [regression] change of validation in date array wrongly causes error
Version: 11.4.x-dev » main

This will be fixed on the main branch first, then backported.

cilefen’s picture

It’s important to understand context with regressions. Was it #3241299: Properly return FALSE for invalid strings in DateTimePlus::checkArray() so that the correct exception is thrown that changed the behavior, or another change?

jjeffrie’s picture

This issue breaks the DateTime field in webforms as well.