MVC and request handling · Question 10 of 12
A form sends the field startDate as "2026-10-15" to createAction(Conference $conference); the property is a \DateTime. How is the value mapped correctly?
1 answer is correct. Medium
Show answer
Answer
- C Set the date format in initializeCreateAction() via the property mapping configuration of the argument (DateTimeConverter::CONFIGURATION_DATE_FORMAT = 'Y-m-d')
Explanation
Without further configuration the DateTimeConverter expects the W3C format including the time (e.g. 2026-10-15T00:00:00+02:00); "2026-10-15" does not match and the mapping fails. $this->arguments->getArgument('conference')->getPropertyMappingConfiguration()->forProperty('startDate')->setTypeConverterOption(DateTimeConverter::class, DateTimeConverter::CONFIGURATION_DATE_FORMAT, 'Y-m-d') sets the format. The TCA only affects the backend, and a validator does not convert anything.