Project

General

Profile

Actions

Bug #104962

open

TypeError in xml2array if flexform is NULL

Added by Franz Holzinger 2 months ago. Updated about 2 months ago.

Status:
Needs Feedback
Priority:
Should have
Assignee:
-
Category:
FormEngine aka TCEforms
Target version:
-
Start date:
2024-09-13
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
13
PHP Version:
8.3
Tags:
flexform
Complexity:
Is Regression:
Sprint Focus:

Description

If no flexform value has been entered, then it is stored as NULL in the database table.
This however leads to a TypeError in PHP 8.3.11.

(1/1) TypeError TYPO3\CMS\Core\Utility\GeneralUtility::xml2array(): Argument #1 ($string) must be of type string, null given, called in /path/typo3_src-13.2.1.test/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaFlexPrepare.php on line 104
in /path/typo3_src-13.2.1.test/typo3/sysext/core/Classes/Utility/GeneralUtility.php line 1265
  • @return array|string If the parsing had errors, a string with the error message is returned. Otherwise an array with the content. * @see array2xml() * @see xml2arrayProcess()
    */
public static function xml2array(string $string, string $NSprefix = '', bool $reportDocTag = false): array|string
{
$runtimeCache = static::makeInstance(CacheManager::class)->getCache('runtime');
$firstLevelCache = $runtimeCache->get('generalUtilityXml2Array') ?: [];
$identifier = md5($string . $NSprefix . ($reportDocTag ? '1' : '0'));

at TYPO3\CMS\Core\Utility\GeneralUtility::xml2array(null)
in /path/typo3_src-13.2.1.test/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaFlexPrepare.php line 104

if (isset($result['databaseRow'][$fieldName])) {
$valueArray = $result['databaseRow'][$fieldName];
}
if (!is_array($result['databaseRow'][$fieldName])) {
$valueArray = GeneralUtility::xml2array($result['databaseRow'][$fieldName]);
}
if (!is_array($valueArray)) {
$valueArray = [];
}
Actions #1

Updated by Garvin Hicking 2 months ago

  • Category changed from Backend API to FormEngine aka TCEforms
  • Status changed from New to Needs Feedback
  • Tags set to flexform

Thanks for the report!

Can you please specify a minimal example of i.e. a flexform/tca config to reproduce this? Maybe using an EXT:styleguide is possible, can you tell steps to reproduce this?

Actions #2

Updated by Franz Holzinger 2 months ago

I am not able to write a new extension for this case. I just used tt_products where article records are created. One article has no graduated price configuration flexform: graduated_config

https://github.com/franzholz/tt_products/blob/master/Configuration/TCA/tt_products_articles.php

This flexform leads to the exception if the graduated config of an article is NULL.

Actions #3

Updated by Garvin Hicking 2 months ago

Thanks for the feedback. If you are able to provide a smaller, isolated example at some point, we might be able to help. tt_products is too big and loaded with dependencies we cannot properly debug within reasonable time.

Actions #4

Updated by Stefan Bürk 2 months ago

@Franz Holzinger As a quick solution for you

  • fix your database and ensure to have tt_content.pi_flexform set to at least an empty string and not null
  • use proper api (DataHandler) to write records OR ensure to provide valid data, for example for the pi_flexform field
  • if using for example QueryBuilder or connection lowlevel api ensure to at least write pi_flexform at least with an empty string.

TYPO3 core have a TCA default value which means that DataHandler / Backend formengine takes care of that.

With TYPO3 we could have a look into making pi_flexform a not nullable with a empty string db default field (database default) which was not possible in earlier version due to "db constraints" all supported databases.

check for beeing a string before using this method at this place may be added, however there should either be already an array or a string anyway.

Actions #5

Updated by Franz Holzinger about 2 months ago

1.) Is it really necessary to make such a change where the table field for flexforms must not be any more NULL but an empty string?

I ask this because the table tt_content has the column field pi_flexform which has many NULL entries. Shouldn't then the same database table field state be allowed for all other flexforms as well?

Actions #6

Updated by Franz Holzinger about 2 months ago

The error message disappears if I change all NULL values of flexforms into empy strings ''.

UPDATE `tt_products_articles` SET graduated_config = '' WHERE graduated_config  IS NULL

If this is required for an upgrade to TYPO3 13 then an upgrade wizard in the Install Tool would be necessary. Is it planned to ship one with TYPO3?

Actions

Also available in: Atom PDF