Bug #82554
closedBackend column with eval datetime and null checkbox not working as expected
0%
Description
How to reproduce the bug:
Create a TCA column with eval "datetime" and "null" and a database table column of type "datetime" that is nullable.
Expected behaviour:
When the checkbox is unchecked null will be saved to database as the column value. This works as expected.
When the checkbox is checked and a date is supplied this will be saved to dabase. Working as expected.
But when you edit an item the checkbox will always be checked even if the table column is null. This is because the databaseRow value is "0" but the checkbox checks for "null". Simply put: You edit an item but don't even touch the date fields. Just save it. As the checkbox is checked the database table column will now save a datetime of "0000-00-00 00:00:00" instead of "null".
Fix/Hack:
To fix this for nullable date fields sysext/backend/Classes/Form/FormDataProvider/DatabaseRowDateTimeFields.php can be modified with an additional check for a nullable column.
Quick and dirty example:
...
} else if (empty($result['databaseRow'][$column]) && in_array('null', explode(',', $columnConfig['config']['eval']))) {
$result['databaseRow'][$column] = null;
} else {
...