I have a date that I'd like to set as the default value the current date and most of the posts suggest to add the 'data' => new \DateTime() but there are two issues with that in Sonata:
- if I change the date to a random one or even leave it empty, it will still save in the database the current one
- in the edit view it will override the date from the create view and the value will still be the current date
My code:
$form->add('startDate', DateType::class, [
'required' => false,
'label' => 'Starting date',
'data' => new \DateTime("now"),
'constraints' => ...
])
]);
What am I missing?