setting default value in symfony2 sonata admin bundle

symfony, symfony-sonata

Solution

I presume you've probably already solved this by now, but as a reference to anyone else you can override the getNewInstance() method and set the default value on the object:

public function getNewInstance()
{
    $instance = parent::getNewInstance();
    $instance->setName('my default value');

    return $instance;
}

Problem

how can i set default value in sonata admin bundle the data option is missing in configureFormFields method ``` protected function configureFormFields(FormMapper $formMapper) { $formMapper ->add('name', null, array('required' => true, 'data' => "my default value")) ; } ``` how can use data attribute to set default value inside field ???

Original source