Search code examples
symfonydoctrine-ormsymfony-sonatasonata-admin

How to add non-persistent field to form?


There is SonataAdminBundle and User entity. Admin service for it:

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->add('name')
        // ...
        ->add('send_greeting', 'checkbox')
    ;
}

Field send_greeting is not related to User entity. It required only for admin service (depends it value we would send email or not after saving user). So how it possible add this field to form without binding to entity?


Solution

  • You can set property_path option to false. e.g

    ->add('send_greeting', 'checkbox',array(
       'property_path' => false
    ))
    ...