Issue Bug Closed

#106697TCA: Default record type is removed if (int) 0

Thomas Rawiel 05/14/25, 16:55 updated 12/02/25, 14:21

Description

From this Bug report in EXT:news https://github.com/georgringer/news/issues/2641
I found, that this commit https://github.com/TYPO3/typo3/commit/0d81d8f43788ab40f73e9d4ea62923fa6addf293 introduced the following problem:

Staying with the example of EXT:news, there a 3 valid types (0,1,2)

However, the array_filter function in TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRecordTypeValue::getValidTypeValues() removes the record type with value 0

The result is, that the news record always shows the TCA showitem of for type 1, if the selected type is 0 or 1.

Test: Remove the array_filter()

protected function getValidTypeValues(array $items): array
{
    $test = array_map(static function (array $item) {
        $type = $item['value'] ?? '';
        return $type !== '--div--' ? $type : '';
    }, $items);

    $result_of_array_filter = array_filter($test);

    return $result_of_array_filter;
}

clipboard-202505141849-5lyma.png

If we return $test early, the form is correct. Type 0 showitem is displayed.
If we return $result_of_array_filter the form shows the fields, that are configured in showitem for type 1

array_filter() removes values that are considered falsey by default — including 0 (integer), ‘’ (empty string), false, and null

Possible solution:
add a callback to array_filter that explicitly checks for what you want to keep.

e.g.
$filtered = array_filter($array, function($value) {
return !empty($value) || $value === 0;;
});

Reviews 2