symfonysonata-adminsonatasonata-media-bundle

how to set sonata form data_class on edit


I'm stuck with following error message on a project with symfony 2.8 and sonata admin/media bundle. I log in sonata and navigate to the list view were I have an edit button. I click the edit button and get following error.

error message: The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class DateTime. You can avoid this error by setting the "data_class" option to "DateTime" or by adding a view transformer that transforms an instance of class DateTime to scalar, array or an instance of \ArrayAccess.

I found some answers via stackoverflow saying that the data_class needs to be set on the specific formtype. But thats sonata, were can I find the form I have to work on?


Solution

  • You can describe it in your admin class

    protected function configureFormFields(FormMapper $form)
    {
        $form->add('date', 'datetime', array('data_class' => 'DateTime'));
    }