I have such form definition class:
class HistorySliderType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('date', 'datetime', array(
'date_widget' => 'single_text',
'time_widget' => 'single_text',
'date_format' => 'yyyy-MM-dd',
'with_seconds' => true
));
}
public function getDefaultOptions(array $options)
{
return array(
'data' => array('date' => new \DateTime())
);
}
/**
* {@inheritdoc}
*/
function getName()
{
return 'acme_tbundle_historyslidertype';
}
}
and I expected the date field to be now as default, while the fields stay blank on form rendering.
Am I missing something or getDefaultOptions isn’t supposed to be used to specify the initial (default) form values?
UPD:
After some research I came to the thoughts that it is a bug, so filled it: https://github.com/symfony/symfony/issues/3288
Use the
dataoption when adding the field: