Issue Bug Closed

#99130Form Variants: Dynamic validators on formValues break in PHP 8

David Nax 11/18/22, 10:50 updated 06/27/24, 15:40

Description

Since Version 8 PHP breaks when array key not exists. This affects the usage of dynamic validators of form variants as documented here:
https://docs.typo3.org/c/typo3/cms-form/11.5/en-us/I/Concepts/Variants/Index.html#adding-validators-dynamically.

When we use e.g.

condition: 'formValues["country"] == "GB"'

we get the following error

#1476107295 TYPO3\CMS\Core\Error\Exception
PHP Warning: Undefined array key "country" in /var/www/html/vendor/symfony/expression-language/Node/GetAttrNode.php line 97

A possible explanation is that in TYPO3\CMS\Form\Domain\Runtime\FormRuntime , processVariants() is called a number of times (also when the form is initially rendered), but the formValues (which are filled from the formState and the request arguments, see lines 1124ff. ) remain empty until they are filled later. The condition matcher ( line 476 ) then is invoked to match the condition against an empty array with no keys, resulting in the above error.

Reviews 1